diff --git a/source/glest_game/main/program.h b/source/glest_game/main/program.h index 05f43f51a..e77d4c896 100644 --- a/source/glest_game/main/program.h +++ b/source/glest_game/main/program.h @@ -15,7 +15,7 @@ #include "context.h" #include "platform_util.h" #include "window_gl.h" -#include "socket.h" +#include "socket.h" #include "components.h" using Shared::Graphics::Context; @@ -69,25 +69,25 @@ public: class Program{ private: static const int maxTimes; - - class ShowMessageProgramState : public ProgramState { - GraphicMessageBox msgBox; - int mouseX; - int mouseY; - int mouse2dAnim; - string msg; - bool userWantsExit; - - public: - ShowMessageProgramState(Program *program, const char *msg); - - virtual void render(); - virtual void mouseDownLeft(int x, int y); - virtual void mouseMove(int x, int y, const MouseState &mouseState); - virtual void update(); - virtual bool wantExit() { return userWantsExit; } - }; - + + class ShowMessageProgramState : public ProgramState { + GraphicMessageBox msgBox; + int mouseX; + int mouseY; + int mouse2dAnim; + string msg; + bool userWantsExit; + + public: + ShowMessageProgramState(Program *program, const char *msg); + + virtual void render(); + virtual void mouseDownLeft(int x, int y); + virtual void mouseMove(int x, int y, const MouseState &mouseState); + virtual void update(); + virtual bool wantExit() { return userWantsExit; } + }; + private: ProgramState *programState; @@ -96,13 +96,13 @@ private: PerformanceTimer updateTimer; PerformanceTimer updateCameraTimer; - WindowGl *window; + WindowGl *window; static Program *singleton; public: Program(); - ~Program(); - + ~Program(); + static Program *getInstance() {return singleton;} void initNormal(WindowGl *window); @@ -119,7 +119,7 @@ public: void keyUp(char key); void keyPress(char c); void loop(); - void resize(SizeState sizeState); + void resize(SizeState sizeState); void showMessage(const char *msg); //misc diff --git a/source/glest_game/types/faction_type.cpp b/source/glest_game/types/faction_type.cpp new file mode 100644 index 000000000..1e59d329d --- /dev/null +++ b/source/glest_game/types/faction_type.cpp @@ -0,0 +1,155 @@ +// ============================================================== +// This file is part of Glest (www.glest.org) +// +// Copyright (C) 2001-2008 Martiņo Figueroa +// +// You can redistribute this code and/or modify it under +// the terms of the GNU General Public License as published +// by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version +// ============================================================== + +#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 unitFilenames; + findAll(unitsPath, unitFilenames); + unitTypes.resize(unitFilenames.size()); + for(int i=0; i upgradeFilenames; + findAll(upgradesPath, upgradeFilenames); + upgradeTypes.resize(upgradeFilenames.size()); + for(int i=0; iaddFile(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; igetChild("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; igetChildCount(); ++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; iaddFile(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 diff --git a/source/glest_game/types/tech_tree.cpp b/source/glest_game/types/tech_tree.cpp index 753ae73f4..2af7ccc66 100644 --- a/source/glest_game/types/tech_tree.cpp +++ b/source/glest_game/types/tech_tree.cpp @@ -70,52 +70,38 @@ void TechTree::load(const string &dir, set &factions, Checksum* checksum XmlTree xmlTree; string path= dir+"/"+lastDir(dir)+".xml"; - bool bCanProcessFile = true; -#ifdef _WINDOWS + checksum->addFile(path); - DWORD fileAttributes = GetFileAttributes(path.c_str()); - if( (fileAttributes & FILE_ATTRIBUTE_HIDDEN) == FILE_ATTRIBUTE_HIDDEN) - { - bCanProcessFile = false; + xmlTree.load(path); + const XmlNode *techTreeNode= xmlTree.getRootNode(); + + //attack types + const XmlNode *attackTypesNode= techTreeNode->getChild("attack-types"); + attackTypes.resize(attackTypesNode->getChildCount()); + for(int i=0; igetChild("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; igetChild("armor-type", i); + armorTypes[i].setName(armorTypeNode->getAttribute("name")->getRestrictedValue()); + armorTypes[i].setId(i); + } - if(bCanProcessFile == true) - { - checksum->addFile(path); - - xmlTree.load(path); - const XmlNode *techTreeNode= xmlTree.getRootNode(); - - //attack types - const XmlNode *attackTypesNode= techTreeNode->getChild("attack-types"); - attackTypes.resize(attackTypesNode->getChildCount()); - for(int i=0; igetChild("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; igetChild("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; igetChildCount(); ++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); - } + //damage multipliers + damageMultiplierTable.init(attackTypes.size(), armorTypes.size()); + const XmlNode *damageMultipliersNode= techTreeNode->getChild("damage-multipliers"); + for(int i=0; igetChildCount(); ++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){ diff --git a/source/glest_game/types/unit_type.cpp b/source/glest_game/types/unit_type.cpp index 04902bf38..d2f9f3827 100644 --- a/source/glest_game/types/unit_type.cpp +++ b/source/glest_game/types/unit_type.cpp @@ -101,17 +101,6 @@ void UnitType::load(int id,const string &dir, const TechTree *techTree, const Fa //file load 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); XmlTree xmlTree; diff --git a/source/glest_game/types/upgrade_type.cpp b/source/glest_game/types/upgrade_type.cpp new file mode 100644 index 000000000..ef4072dd2 --- /dev/null +++ b/source/glest_game/types/upgrade_type.cpp @@ -0,0 +1,209 @@ +// ============================================================== +// This file is part of Glest (www.glest.org) +// +// Copyright (C) 2001-2008 Martiņo Figueroa +// +// You can redistribute this code and/or modify it under +// the terms of the GNU General Public License as published +// by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version +// ============================================================== + +#include "upgrade_type.h" + +#include +#include + +#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; igetChildCount(); ++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; igetChildCount(); ++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; igetChild("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; igetChildCount(); ++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; igetName()+"\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 diff --git a/source/glest_game/world/tileset.cpp b/source/glest_game/world/tileset.cpp index 63ac06fcf..fcff4e9b7 100644 --- a/source/glest_game/world/tileset.cpp +++ b/source/glest_game/world/tileset.cpp @@ -108,16 +108,6 @@ void Tileset::load(const string &dir, Checksum *checksum){ string name= lastDir(dir); 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); try{ diff --git a/source/shared_lib/sources/platform/win32/platform_util.cpp b/source/shared_lib/sources/platform/win32/platform_util.cpp index e14f9d33d..d4d1eef18 100644 --- a/source/shared_lib/sources/platform/win32/platform_util.cpp +++ b/source/shared_lib/sources/platform/win32/platform_util.cpp @@ -224,8 +224,7 @@ void findAll(const string &path, vector &results, bool cutExtension, boo do{ SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] fi.name [%s]\n",__FILE__,__FUNCTION__,__LINE__,fi.name); - DWORD fileAttributes = GetFileAttributes(fi.name); - if( (fileAttributes != INVALID_FILE_ATTRIBUTES && ((fileAttributes & FILE_ATTRIBUTE_HIDDEN) == FILE_ATTRIBUTE_HIDDEN)) || (fi.attrib & _A_HIDDEN) == _A_HIDDEN) { + if((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); } else @@ -264,14 +263,6 @@ bool isdir(const char *path) { struct stat stats; 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); return ret;