From 372442d181bedb0d2ba7c244841248eb557685d3 Mon Sep 17 00:00:00 2001 From: titiger Date: Sun, 22 Dec 2013 01:36:54 +0100 Subject: [PATCH 01/18] Render order changed to get better render results with units using semi-transparent textures. --- source/glest_game/game/game.cpp | 18 +++++++++++------- source/glest_game/graphics/renderer.cpp | 11 ++++++++--- source/glest_game/graphics/renderer.h | 2 +- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index 6afc25c9..51b60acc 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -5171,9 +5171,13 @@ void Game::render3d(){ if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] renderFps = %d took msecs: %lld [renderObjects]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,renderFps,chrono.getMillis()); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start(); + //objects + renderer.renderObjects(avgRenderFps); + if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] renderFps = %d took msecs: %lld [renderObjects]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,renderFps,chrono.getMillis()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start(); - //units - renderer.renderUnits(avgRenderFps); + //ground units + renderer.renderUnits(false, avgRenderFps); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] renderFps = %d took msecs: %lld [renderUnits]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,renderFps,chrono.getMillis()); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start(); @@ -5183,10 +5187,6 @@ void Game::render3d(){ if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] renderFps = %d took msecs: %lld [renderObjects]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,renderFps,chrono.getMillis()); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start(); } - //objects - renderer.renderObjects(avgRenderFps); - if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] renderFps = %d took msecs: %lld [renderObjects]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,renderFps,chrono.getMillis()); - if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start(); //water renderer.renderWater(); @@ -5194,12 +5194,16 @@ void Game::render3d(){ if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] renderFps = %d took msecs: %lld [renderWater]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,renderFps,chrono.getMillis()); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start(); + //air units + renderer.renderUnits(true, avgRenderFps); + if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] renderFps = %d took msecs: %lld [renderUnits]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,renderFps,chrono.getMillis()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start(); + //particles renderer.renderParticleManager(rsGame); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] renderFps = %d took msecs: %lld [renderParticleManager]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,renderFps,chrono.getMillis()); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start(); - //mouse 3d renderer.renderMouse3d(); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] renderFps = %d took msecs: %lld [renderMouse3d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,renderFps,chrono.getMillis()); diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index 9cc64980..06410e35 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -4747,6 +4747,8 @@ void Renderer::renderWater() { glDisable(GL_TEXTURE_2D); glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + if(textures3D) { Texture3D *waterTex= world->getTileset()->getWaterTex(); if(waterTex == NULL) { @@ -5030,7 +5032,7 @@ void Renderer::renderGhostModel(const UnitType *building, const Vec2i pos,Cardin glPopMatrix(); } -void Renderer::renderUnits(const int renderFps) { +void Renderer::renderUnits(bool airUnits, const int renderFps) { if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) { return; } @@ -5057,6 +5059,9 @@ void Renderer::renderUnits(const int renderFps) { visibleUnitIndex < (int)qCache.visibleQuadUnitList.size(); ++visibleUnitIndex) { Unit *unit = qCache.visibleQuadUnitList[visibleUnitIndex]; + if(( airUnits==false && unit->getType()->getField()==fAir) || ( airUnits==true && unit->getType()->getField()!=fAir)){ + continue; + } meshCallbackTeamColor.setTeamTexture(unit->getFaction()->getTexture()); if(modelRenderStarted == false) { @@ -5108,8 +5113,8 @@ void Renderer::renderUnits(const int renderFps) { } else { glEnable(GL_COLOR_MATERIAL); - //this only needs to be done in render fast for selection and shadow calculation. No need to do this in real render - //glAlphaFunc(GL_GREATER, 0.4f); + // we cut off a tiny bit here to avoid problems with fully transparent texture parts cutting units in background rendered later. + glAlphaFunc(GL_GREATER, 0.02f); } //render diff --git a/source/glest_game/graphics/renderer.h b/source/glest_game/graphics/renderer.h index 2c48c730..15ce157c 100644 --- a/source/glest_game/graphics/renderer.h +++ b/source/glest_game/graphics/renderer.h @@ -545,7 +545,7 @@ public: void renderObjects(const int renderFps); void renderWater(); - void renderUnits(const int renderFps); + void renderUnits(bool airUnits, const int renderFps); void renderUnitsToBuild(const int renderFps); void renderSelectionEffects(); From f8c497f6dc4734e06a463949ed3f7d5d011fa6bc Mon Sep 17 00:00:00 2001 From: SoftCoder Date: Sat, 21 Dec 2013 21:53:27 -0800 Subject: [PATCH 02/18] - in progress work to try to get attack boosts loading from a saved game (not working yet and commented out) --- source/glest_game/graphics/particle_type.cpp | 40 ++++++ source/glest_game/graphics/particle_type.h | 1 + .../graphics/unit_particle_type.cpp | 25 ++++ .../glest_game/graphics/unit_particle_type.h | 1 + source/glest_game/type_instances/unit.cpp | 116 ++++++++++++++++-- source/glest_game/type_instances/unit.h | 13 +- source/glest_game/types/skill_type.cpp | 33 +++++ source/glest_game/types/skill_type.h | 1 + source/glest_game/world/world.cpp | 20 +++ source/glest_game/world/world.h | 1 + 10 files changed, 242 insertions(+), 9 deletions(-) diff --git a/source/glest_game/graphics/particle_type.cpp b/source/glest_game/graphics/particle_type.cpp index eb1b99e5..b553cd2b 100644 --- a/source/glest_game/graphics/particle_type.cpp +++ b/source/glest_game/graphics/particle_type.cpp @@ -315,6 +315,46 @@ void ParticleSystemType::setValues(AttackParticleSystem *ats){ ats->setBlendMode(ParticleSystem::strToBlendMode(mode)); } +void ParticleSystemType::loadGame(const XmlNode *rootNode) { + const XmlNode *particleSystemTypeNode = rootNode->getChild("ParticleSystemType"); + + type = particleSystemTypeNode->getAttribute("type")->getIntValue(); + + modelCycle = particleSystemTypeNode->getAttribute("modelCycle")->getFloatValue(); + primitive = particleSystemTypeNode->getAttribute("primitive")->getValue(); + offset = Vec3f::strToVec3(particleSystemTypeNode->getAttribute("offset")->getValue()); + color = Vec4f::strToVec4(particleSystemTypeNode->getAttribute("color")->getValue()); + colorNoEnergy = Vec4f::strToVec4(particleSystemTypeNode->getAttribute("colorNoEnergy")->getValue()); + size = particleSystemTypeNode->getAttribute("size")->getFloatValue(); + sizeNoEnergy = particleSystemTypeNode->getAttribute("sizeNoEnergy")->getFloatValue(); + speed = particleSystemTypeNode->getAttribute("speed")->getFloatValue(); + gravity = particleSystemTypeNode->getAttribute("gravity")->getFloatValue(); + emissionRate = particleSystemTypeNode->getAttribute("emissionRate")->getFloatValue(); + energyMax = particleSystemTypeNode->getAttribute("energyMax")->getIntValue(); + energyVar = particleSystemTypeNode->getAttribute("energyVar")->getIntValue(); + mode = particleSystemTypeNode->getAttribute("mode")->getValue(); + teamcolorNoEnergy = particleSystemTypeNode->getAttribute("teamcolorNoEnergy")->getIntValue(); + teamcolorEnergy = particleSystemTypeNode->getAttribute("teamcolorEnergy")->getIntValue(); + alternations = particleSystemTypeNode->getAttribute("alternations")->getIntValue(); + particleSystemStartDelay = particleSystemTypeNode->getAttribute("particleSystemStartDelay")->getIntValue(); + + if(particleSystemTypeNode->hasChild("UnitParticleSystemType")) { + vector particleSystemTypeNodeList = particleSystemTypeNode->getChildList("UnitParticleSystemType"); + for(unsigned int i = 0; i < particleSystemTypeNodeList.size(); ++i) { + XmlNode *node = particleSystemTypeNodeList[i]; + + UnitParticleSystemType *child = new UnitParticleSystemType(); + child->loadGame(node); + children.push_back(child); + } + } + + minmaxEnabled = particleSystemTypeNode->getAttribute("minmaxEnabled")->getIntValue(); + minHp = particleSystemTypeNode->getAttribute("minHp")->getIntValue(); + maxHp = particleSystemTypeNode->getAttribute("maxHp")->getIntValue(); + minmaxIsPercent = particleSystemTypeNode->getAttribute("minmaxIsPercent")->getIntValue(); +} + void ParticleSystemType::saveGame(XmlNode *rootNode) { std::map mapTagReplacements; XmlNode *particleSystemTypeNode = rootNode->addChild("ParticleSystemType"); diff --git a/source/glest_game/graphics/particle_type.h b/source/glest_game/graphics/particle_type.h index dea1436d..36975922 100644 --- a/source/glest_game/graphics/particle_type.h +++ b/source/glest_game/graphics/particle_type.h @@ -111,6 +111,7 @@ public: string getType() const { return type; }; virtual void saveGame(XmlNode *rootNode); + virtual void loadGame(const XmlNode *rootNode); protected: diff --git a/source/glest_game/graphics/unit_particle_type.cpp b/source/glest_game/graphics/unit_particle_type.cpp index a6639029..bc2adbd4 100644 --- a/source/glest_game/graphics/unit_particle_type.cpp +++ b/source/glest_game/graphics/unit_particle_type.cpp @@ -291,6 +291,31 @@ void UnitParticleSystemType::load(const XmlNode *particleFileNode, const string } } +void UnitParticleSystemType::loadGame(const XmlNode *rootNode) { + ParticleSystemType::loadGame(rootNode); + + const XmlNode *unitParticleSystemTypeNode = rootNode->getChild("UnitParticleSystemType"); + + shape = static_cast(unitParticleSystemTypeNode->getAttribute("shape")->getIntValue()); + angle = unitParticleSystemTypeNode->getAttribute("angle")->getFloatValue(); + radius = unitParticleSystemTypeNode->getAttribute("radius")->getFloatValue(); + minRadius = unitParticleSystemTypeNode->getAttribute("minRadius")->getFloatValue(); + emissionRateFade = unitParticleSystemTypeNode->getAttribute("emissionRateFade")->getFloatValue(); + direction = Vec3f::strToVec3(unitParticleSystemTypeNode->getAttribute("direction")->getValue()); + relative = unitParticleSystemTypeNode->getAttribute("relative")->getIntValue(); + relativeDirection = unitParticleSystemTypeNode->getAttribute("relativeDirection")->getIntValue(); + fixed = unitParticleSystemTypeNode->getAttribute("fixed")->getIntValue(); + staticParticleCount = unitParticleSystemTypeNode->getAttribute("staticParticleCount")->getIntValue(); + isVisibleAtNight = unitParticleSystemTypeNode->getAttribute("isVisibleAtNight")->getIntValue(); + isVisibleAtDay = unitParticleSystemTypeNode->getAttribute("isVisibleAtDay")->getIntValue(); + isDaylightAffected = unitParticleSystemTypeNode->getAttribute("isDaylightAffected")->getIntValue(); + radiusBasedStartenergy = unitParticleSystemTypeNode->getAttribute("radiusBasedStartenergy")->getIntValue(); + delay = unitParticleSystemTypeNode->getAttribute("delay")->getIntValue(); + lifetime = unitParticleSystemTypeNode->getAttribute("lifetime")->getIntValue(); + startTime = unitParticleSystemTypeNode->getAttribute("startTime")->getFloatValue(); + endTime = unitParticleSystemTypeNode->getAttribute("endTime")->getFloatValue(); +} + void UnitParticleSystemType::saveGame(XmlNode *rootNode) { ParticleSystemType::saveGame(rootNode); diff --git a/source/glest_game/graphics/unit_particle_type.h b/source/glest_game/graphics/unit_particle_type.h index 17ed5232..c6dfda8c 100644 --- a/source/glest_game/graphics/unit_particle_type.h +++ b/source/glest_game/graphics/unit_particle_type.h @@ -89,6 +89,7 @@ public: const void setValues (UnitParticleSystem *uts); bool hasTexture() const { return(texture != NULL); } virtual void saveGame(XmlNode *rootNode); + virtual void loadGame(const XmlNode *rootNode); }; class ObjectParticleSystemType: public UnitParticleSystemType { diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index b34e57ba..cfd1a121 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -273,6 +273,8 @@ UnitAttackBoostEffect::UnitAttackBoostEffect() { printf("++ Create UnitAttackBoostEffect [%p] after count = %d\n",this,memoryObjectList[this]); } + unitId = -1; + unitPtr = NULL; boost = NULL; source = NULL; ups = NULL; @@ -303,6 +305,51 @@ UnitAttackBoostEffect::~UnitAttackBoostEffect() { upst = NULL; } +const Unit * UnitAttackBoostEffect::getSource() { + if(source == NULL && unitPtr != NULL && unitId > 0) { + source = unitPtr->getFaction()->findUnit(unitId); + } + return source; +} + +void UnitAttackBoostEffect::setSource(const Unit *unit) { + source = unit; +} + +void UnitAttackBoostEffect::loadGame(const XmlNode *rootNode, Unit *unit, const SkillType *skillType) { + //const XmlNode *unitAttackBoostEffectOriginatorNode = rootNode->getChild("UnitAttackBoostEffect"); + const XmlNode *unitAttackBoostEffectOriginatorNode = rootNode; + + AttackBoost *load_boost = new AttackBoost(); + load_boost->loadGame(unitAttackBoostEffectOriginatorNode,unit->getFaction(),skillType); + boost = load_boost; + + if(unitAttackBoostEffectOriginatorNode->hasAttribute("source") == true) { + unitId = unitAttackBoostEffectOriginatorNode->getAttribute("source")->getIntValue(); + unitPtr = unit; + source = unit->getFaction()->findUnit(unitId); + } + + if(unitAttackBoostEffectOriginatorNode->hasChild("UnitParticleSystemType") == true) { + //const XmlNode *node = unitAttackBoostEffectOriginatorNode->getChild("UnitParticleSystemType"); + + upst = new UnitParticleSystemType(); + upst->loadGame(unitAttackBoostEffectOriginatorNode); + } + + if(unitAttackBoostEffectOriginatorNode->hasChild("UnitParticleSystem") == true) { + const XmlNode *node = unitAttackBoostEffectOriginatorNode->getChild("UnitParticleSystem"); + + ups = new UnitParticleSystem(200); + ups->loadGame(node); + + ups->setParticleOwner(unit); + upst->setValues(ups); + + Renderer::getInstance().addToDeferredParticleSystemList(make_pair(ups, rsGame)); + } +} + void UnitAttackBoostEffect::saveGame(XmlNode *rootNode) { std::map mapTagReplacements; XmlNode *unitAttackBoostEffectNode = rootNode->addChild("UnitAttackBoostEffect"); @@ -336,6 +383,43 @@ UnitAttackBoostEffectOriginator::~UnitAttackBoostEffectOriginator() { currentAppliedEffect = NULL; } +void UnitAttackBoostEffectOriginator::loadGame(const XmlNode *rootNode, Unit *unit) { + const XmlNode *unitAttackBoostEffectOriginatorNode = rootNode->getChild("UnitAttackBoostEffectOriginator"); + + SkillClass skillClass = scStop; + string skillTypeName = unitAttackBoostEffectOriginatorNode->getAttribute("skillType")->getValue(); + if(unitAttackBoostEffectOriginatorNode->hasAttribute("skillClass") == false) { + int skillCount = unit->getType()->getSkillTypeCount(); + for(int index = 0; index < skillCount; ++index) { + const SkillType *st = unit->getType()->getSkillType(index); + if(st->getName() == skillTypeName) { + skillClass = st->getClass(); + break; + } + } + } + else { + skillClass = static_cast(unitAttackBoostEffectOriginatorNode->getAttribute("skillClass")->getIntValue()); + } + + this->skillType = unit->getType()->getSkillType(skillTypeName,skillClass); + + if(unitAttackBoostEffectOriginatorNode->hasChild("currentAttackBoostUnits") == true) { + vector currentAttackBoostUnitsNodeList = unitAttackBoostEffectOriginatorNode->getChildList("currentAttackBoostUnits"); + for(unsigned int i = 0; i < currentAttackBoostUnitsNodeList.size(); ++i) { + XmlNode *node = currentAttackBoostUnitsNodeList[i]; + + int unitId = node->getAttribute("value")->getIntValue(); + currentAttackBoostUnits.push_back(unitId); + } + } + + if(unitAttackBoostEffectOriginatorNode->hasChild("UnitAttackBoostEffect") == true) { + currentAppliedEffect = new UnitAttackBoostEffect(); + currentAppliedEffect->loadGame(unitAttackBoostEffectOriginatorNode, unit,this->skillType); + } +} + void UnitAttackBoostEffectOriginator::saveGame(XmlNode *rootNode) { std::map mapTagReplacements; XmlNode *unitAttackBoostEffectOriginatorNode = rootNode->addChild("UnitAttackBoostEffectOriginator"); @@ -343,6 +427,7 @@ void UnitAttackBoostEffectOriginator::saveGame(XmlNode *rootNode) { // const SkillType *skillType; if(skillType != NULL) { unitAttackBoostEffectOriginatorNode->addAttribute("skillType",skillType->getName(), mapTagReplacements); + unitAttackBoostEffectOriginatorNode->addAttribute("skillClass",intToStr(skillType->getClass()), mapTagReplacements); } // std::vector currentAttackBoostUnits; for(unsigned int i = 0; i < currentAttackBoostUnits.size(); ++i) { @@ -2598,12 +2683,12 @@ void Unit::updateTimedParticles() { } } -bool Unit::unitHasAttackBoost(const AttackBoost *boost, const Unit *source) const { +bool Unit::unitHasAttackBoost(const AttackBoost *boost, const Unit *source) { bool result = false; for(unsigned int i = 0; i < currentAttackBoostEffects.size(); ++i) { - const UnitAttackBoostEffect *effect = currentAttackBoostEffects[i]; + UnitAttackBoostEffect *effect = currentAttackBoostEffects[i]; if( effect != NULL && effect->boost->name == boost->name && - effect->source->getType()->getId() == source->getType()->getId()) { + effect->getSource()->getType()->getId() == source->getType()->getId()) { result = true; break; } @@ -2635,7 +2720,7 @@ bool Unit::applyAttackBoost(const AttackBoost *boost, const Unit *source) { UnitAttackBoostEffect *effect = new UnitAttackBoostEffect(); effect->boost = boost; - effect->source = source; + effect->setSource(source); bool wasAlive = alive; int originalHp = hp; @@ -2842,7 +2927,7 @@ void Unit::deapplyAttackBoost(const AttackBoost *boost, const Unit *source) { for(unsigned int i = 0; i < currentAttackBoostEffects.size(); ++i) { UnitAttackBoostEffect *effect = currentAttackBoostEffects[i]; - if(effect != NULL && effect->boost == boost && effect->source == source) { + if(effect != NULL && effect->boost == boost && effect->getSource() == source) { delete effect; currentAttackBoostEffects.erase(currentAttackBoostEffects.begin() + i); break; @@ -3337,7 +3422,7 @@ bool Unit::morph(const MorphCommandType *mct) { for(int i = (int)currentAttackBoostEffects.size() - 1; i >= 0; --i) { UnitAttackBoostEffect *effect = currentAttackBoostEffects[i]; if(effect != NULL) { - Unit *sourceUnit = game->getWorld()->findUnitById(effect->source->getId()); + Unit *sourceUnit = game->getWorld()->findUnitById(effect->getSource()->getId()); if(sourceUnit == NULL) { throw megaglest_runtime_error("sourceUnit == NULL"); } @@ -5054,13 +5139,30 @@ Unit * Unit::loadGame(const XmlNode *rootNode, GameSettings *settings, Faction * // int maxQueuedCommandDisplayCount; result->maxQueuedCommandDisplayCount = unitNode->getAttribute("maxQueuedCommandDisplayCount")->getIntValue(); // UnitAttackBoostEffectOriginator currentAttackBoostOriginatorEffect; -// currentAttackBoostOriginatorEffect.saveGame(unitNode); + + // !!! TODO: Softcoder - in progress work to load attack boosts, not working properly yet + //result->currentAttackBoostOriginatorEffect.loadGame(unitNode,result); + // std::vector currentAttackBoostEffects; // for(unsigned int i = 0; i < currentAttackBoostEffects.size(); ++i) { // UnitAttackBoostEffect *uabe= currentAttackBoostEffects[i]; // uabe->saveGame(unitNode); // } + // !!! TODO: Softcoder - in progress work to load attack boosts, not working properly yet +// if(unitNode->hasChild("UnitAttackBoostEffect") == true) { +// vector unitParticleSystemNodeList = unitNode->getChildList("UnitAttackBoostEffect"); +// for(unsigned int i = 0; i < unitParticleSystemNodeList.size(); ++i) { +// XmlNode *node = unitParticleSystemNodeList[i]; +// +// UnitAttackBoostEffect *attackBoostEffect = new UnitAttackBoostEffect(); +// attackBoostEffect->loadGame(node,result,result->getCurrSkill()); +// +// result->currentAttackBoostEffects.push_back(attackBoostEffect); +// } +// } + + // Mutex *mutexCommands; // // //static Mutex mutexDeletedUnits; diff --git a/source/glest_game/type_instances/unit.h b/source/glest_game/type_instances/unit.h index 44882363..16877ec4 100644 --- a/source/glest_game/type_instances/unit.h +++ b/source/glest_game/type_instances/unit.h @@ -295,17 +295,25 @@ public: // =============================== class UnitAttackBoostEffect { +private: + int unitId; + const Unit *unitPtr; + + const Unit *source; public: UnitAttackBoostEffect(); virtual ~UnitAttackBoostEffect(); const AttackBoost *boost; - const Unit *source; + //const Unit *source; + const Unit * getSource(); + void setSource(const Unit *unit); UnitParticleSystem *ups; UnitParticleSystemType *upst; virtual void saveGame(XmlNode *rootNode); + virtual void loadGame(const XmlNode *rootNode, Unit *unit, const SkillType *skillType); }; class UnitAttackBoostEffectOriginator { @@ -319,6 +327,7 @@ public: UnitAttackBoostEffect *currentAppliedEffect; virtual void saveGame(XmlNode *rootNode); + virtual void loadGame(const XmlNode *rootNode, Unit *unit); }; class Unit : public BaseColorPickEntity, ValueCheckerVault, public ParticleOwner { @@ -498,7 +507,7 @@ public: Vec2i getCurrentPathFinderDesiredFinalPos() const { return currentPathFinderDesiredFinalPos; } const UnitAttackBoostEffectOriginator & getAttackBoostOriginatorEffect() const { return currentAttackBoostOriginatorEffect; } - bool unitHasAttackBoost(const AttackBoost *boost, const Unit *source) const; + bool unitHasAttackBoost(const AttackBoost *boost, const Unit *source); inline uint32 getPathfindFailedConsecutiveFrameCount() const { return pathfindFailedConsecutiveFrameCount; } inline void incrementPathfindFailedConsecutiveFrameCount() { pathfindFailedConsecutiveFrameCount++; } diff --git a/source/glest_game/types/skill_type.cpp b/source/glest_game/types/skill_type.cpp index dccc40dd..b71e07aa 100644 --- a/source/glest_game/types/skill_type.cpp +++ b/source/glest_game/types/skill_type.cpp @@ -205,6 +205,39 @@ string AttackBoost::getDesc(bool translatedValue) const{ return ""; } +void AttackBoost::loadGame(const XmlNode *rootNode, Faction *faction, const SkillType *skillType) { + const XmlNode *attackBoostNode = rootNode->getChild("AttackBoost"); + + enabled = attackBoostNode->getAttribute("enabled")->getIntValue(); + allowMultipleBoosts = attackBoostNode->getAttribute("allowMultipleBoosts")->getIntValue(); + radius = attackBoostNode->getAttribute("radius")->getIntValue(); + targetType = static_cast(attackBoostNode->getAttribute("targetType")->getIntValue()); + + if(attackBoostNode->hasChild("UnitType") == true) { + vector attackBoostNodeList = attackBoostNode->getChildList("UnitType"); + for(unsigned int i = 0; i < attackBoostNodeList.size(); ++i) { + XmlNode *node = attackBoostNodeList[i]; + + string unitTypeName = node->getAttribute("name")->getValue(); + const UnitType *unitType = faction->getType()->getUnitType(unitTypeName); + if(unitType != NULL) { + boostUnitList.push_back(unitType); + } + } + } + //boostUpgrade.loadGame(attackBoostNode,faction); + boostUpgrade = skillType->getAttackBoost()->boostUpgrade; + + unitParticleSystemTypeForSourceUnit = new UnitParticleSystemType(); + unitParticleSystemTypeForSourceUnit->loadGame(attackBoostNode); + + unitParticleSystemTypeForAffectedUnit = new UnitParticleSystemType(); + unitParticleSystemTypeForAffectedUnit->loadGame(attackBoostNode); + + includeSelf = attackBoostNode->getAttribute("includeSelf")->getIntValue(); + name = attackBoostNode->getAttribute("name")->getValue(); +} + void AttackBoost::saveGame(XmlNode *rootNode) const { std::map mapTagReplacements; XmlNode *attackBoostNode = rootNode->addChild("AttackBoost"); diff --git a/source/glest_game/types/skill_type.h b/source/glest_game/types/skill_type.h index 0bd9c56b..15e8369b 100644 --- a/source/glest_game/types/skill_type.h +++ b/source/glest_game/types/skill_type.h @@ -109,6 +109,7 @@ public: virtual string getDesc(bool translatedValue) const; virtual void saveGame(XmlNode *rootNode) const; + virtual void loadGame(const XmlNode *rootNode, Faction *faction, const SkillType *skillType); }; class AnimationAttributes { diff --git a/source/glest_game/world/world.cpp b/source/glest_game/world/world.cpp index b9de5458..b559a372 100644 --- a/source/glest_game/world/world.cpp +++ b/source/glest_game/world/world.cpp @@ -1095,6 +1095,26 @@ const UnitType* World::findUnitTypeById(const FactionType* factionType, int id) return NULL; } +const UnitType * World::findUnitTypeByName(const string factionName, const string unitTypeName) { + const UnitType *unitTypeResult = NULL; + + for(int index = 0; unitTypeResult == NULL && index < getFactionCount(); ++index) { + const Faction *faction = getFaction(index); + if(factionName == "" || factionName == faction->getType()->getName(false)) { + for(int unitIndex = 0; + unitTypeResult == NULL && unitIndex < faction->getType()->getUnitTypeCount(); ++unitIndex) { + + const UnitType *unitType = faction->getType()->getUnitType(unitIndex); + if(unitType != NULL && unitType->getName(false) == unitTypeName) { + unitTypeResult = unitType; + break; + } + } + } + } + return unitTypeResult; +} + //looks for a place for a unit around a start location, returns true if succeded bool World::placeUnit(const Vec2i &startLoc, int radius, Unit *unit, bool spaciated) { if(unit == NULL) { diff --git a/source/glest_game/world/world.h b/source/glest_game/world/world.h index 6c36fa14..97a6ea55 100644 --- a/source/glest_game/world/world.h +++ b/source/glest_game/world/world.h @@ -209,6 +209,7 @@ public: void update(); Unit* findUnitById(int id) const; const UnitType* findUnitTypeById(const FactionType* factionType, int id); + const UnitType *findUnitTypeByName(const string factionName, const string unitTypeName); bool placeUnit(const Vec2i &startLoc, int radius, Unit *unit, bool spaciated= false); void moveUnitCells(Unit *unit); From d01e026db944b699ad1751e466ccc9067e0014cc Mon Sep 17 00:00:00 2001 From: SoftCoder Date: Sun, 22 Dec 2013 09:20:25 -0800 Subject: [PATCH 03/18] - escape double quote in cmake module to cleanup warning --- mk/cmake/Modules/FindMiniupnpc.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mk/cmake/Modules/FindMiniupnpc.cmake b/mk/cmake/Modules/FindMiniupnpc.cmake index 2fac1dab..adcc2a11 100644 --- a/mk/cmake/Modules/FindMiniupnpc.cmake +++ b/mk/cmake/Modules/FindMiniupnpc.cmake @@ -150,7 +150,7 @@ if (MINIUPNP_FOUND) static struct IGDdatas data; int main() { - char externalIP[16] = ""; + char externalIP[16] = \"\"; UPNP_GetExternalIPAddress(urls.controlURL, data.first.servicetype, externalIP); return 0; @@ -170,7 +170,7 @@ if (MINIUPNP_FOUND) static struct IGDdatas data; int main() { - char externalIP[16] = ""; + char externalIP[16] = \"\"; UPNP_GetExternalIPAddress(urls.controlURL, data.servicetype, externalIP); return 0; From 6cd1d237ab0ec4722d699f40a80446666c19e4ea Mon Sep 17 00:00:00 2001 From: SoftCoder Date: Sun, 22 Dec 2013 13:18:40 -0800 Subject: [PATCH 04/18] - a little more code cleanup from coverity issues --- .../sources/compression/compression_utils.cpp | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/source/shared_lib/sources/compression/compression_utils.cpp b/source/shared_lib/sources/compression/compression_utils.cpp index cb935957..f65c49b7 100644 --- a/source/shared_lib/sources/compression/compression_utils.cpp +++ b/source/shared_lib/sources/compression/compression_utils.cpp @@ -151,7 +151,9 @@ int zipfile_tool(int argc, const char *argv[]) { if (deflateInit(&stream, level) != Z_OK) { if(SystemFlags::VERBOSE_MODE_ENABLED) printf("deflateInit() failed!\n"); + if(pInfile) fclose(pInfile); + if(pOutfile) fclose(pOutfile); return EXIT_FAILURE; } @@ -163,6 +165,9 @@ int zipfile_tool(int argc, const char *argv[]) { if (fread(s_inbuf, 1, n, pInfile) != n) { if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Failed reading from input file!\n"); + + if(pInfile) fclose(pInfile); + if(pOutfile) fclose(pOutfile); return EXIT_FAILURE; } @@ -180,6 +185,9 @@ int zipfile_tool(int argc, const char *argv[]) { uint n = BUF_SIZE - stream.avail_out; if (fwrite(s_outbuf, 1, n, pOutfile) != n) { if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Failed writing to output file!\n"); + + if(pInfile) fclose(pInfile); + if(pOutfile) fclose(pOutfile); return EXIT_FAILURE; } stream.next_out = s_outbuf; @@ -191,6 +199,7 @@ int zipfile_tool(int argc, const char *argv[]) { } else if (status != Z_OK) { if(SystemFlags::VERBOSE_MODE_ENABLED) printf("deflate() failed with status %i!\n", status); + if(pInfile) fclose(pInfile); if(pOutfile) fclose(pOutfile); return EXIT_FAILURE; @@ -199,6 +208,9 @@ int zipfile_tool(int argc, const char *argv[]) { if (deflateEnd(&stream) != Z_OK) { if(SystemFlags::VERBOSE_MODE_ENABLED) printf("deflateEnd() failed!\n"); + + if(pInfile) fclose(pInfile); + if(pOutfile) fclose(pOutfile); return EXIT_FAILURE; } } @@ -208,6 +220,7 @@ int zipfile_tool(int argc, const char *argv[]) { if (inflateInit(&stream)) { if(SystemFlags::VERBOSE_MODE_ENABLED) printf("inflateInit() failed!\n"); + if(pInfile) fclose(pInfile); if(pOutfile) fclose(pOutfile); return EXIT_FAILURE; @@ -221,6 +234,7 @@ int zipfile_tool(int argc, const char *argv[]) { if (fread(s_inbuf, 1, n, pInfile) != n) { if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Failed reading from input file!\n"); + if(pInfile) fclose(pInfile); if(pOutfile) fclose(pOutfile); return EXIT_FAILURE; @@ -250,6 +264,7 @@ int zipfile_tool(int argc, const char *argv[]) { } else if (status != Z_OK) { if(SystemFlags::VERBOSE_MODE_ENABLED) printf("inflate() failed with status %i!\n", status); + if(pInfile) fclose(pInfile); if(pOutfile) fclose(pOutfile); return EXIT_FAILURE; @@ -258,6 +273,9 @@ int zipfile_tool(int argc, const char *argv[]) { if (inflateEnd(&stream) != Z_OK) { if(SystemFlags::VERBOSE_MODE_ENABLED) printf("inflateEnd() failed!\n"); + + if(pInfile) fclose(pInfile); + if(pOutfile) fclose(pOutfile); return EXIT_FAILURE; } } @@ -269,7 +287,7 @@ int zipfile_tool(int argc, const char *argv[]) { return EXIT_FAILURE; } - fclose(pInfile); + fclose(pInfile); pInfile = 0; if (EOF == fclose(pOutfile)) { if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Failed writing to output file!\n"); return EXIT_FAILURE; From da3c55c00b5b4503d6e431a424a219bf9cf308ac Mon Sep 17 00:00:00 2001 From: SoftCoder Date: Sun, 22 Dec 2013 16:10:00 -0800 Subject: [PATCH 05/18] - bugfix, now support proper saving and reloading of games where attack boost is applied to units --- source/glest_game/graphics/renderer.cpp | 6 + source/glest_game/type_instances/unit.cpp | 130 ++++++++++++++++------ source/glest_game/type_instances/unit.h | 6 +- 3 files changed, 103 insertions(+), 39 deletions(-) diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index 06410e35..98248a38 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -566,6 +566,11 @@ void Renderer::initGame(const Game *game, GameCamera *gameCamera) { } void Renderer::manageDeferredParticleSystems() { + +// if(deferredParticleSystems.empty() == false) { +// printf("deferredParticleSystems.size() = %d\n",(int)deferredParticleSystems.size()); +// } + for(unsigned int i = 0; i < deferredParticleSystems.size(); ++i) { std::pair &deferredParticleSystem = deferredParticleSystems[i]; ParticleSystem *ps = deferredParticleSystem.first; @@ -605,6 +610,7 @@ void Renderer::manageDeferredParticleSystems() { } } manageParticleSystem(ps, rs); + //printf("Managing ps [%p]\n",ps); } deferredParticleSystems.clear(); //printf("After deferredParticleSystems.size() = %d\n",deferredParticleSystems.size()); diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index cfd1a121..47702a5c 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -308,7 +308,10 @@ UnitAttackBoostEffect::~UnitAttackBoostEffect() { const Unit * UnitAttackBoostEffect::getSource() { if(source == NULL && unitPtr != NULL && unitId > 0) { source = unitPtr->getFaction()->findUnit(unitId); + + //printf("#1 Get source - boost effect unitId = %d unitPtr = %s source = %p\n",unitId,unitPtr->getFullName(false).c_str(),source); } + //printf("#2 Get source - boost effect unitId = %d unitPtr = %s source = %p\n",unitId,unitPtr->getFullName(false).c_str(),source); return source; } @@ -316,37 +319,75 @@ void UnitAttackBoostEffect::setSource(const Unit *unit) { source = unit; } -void UnitAttackBoostEffect::loadGame(const XmlNode *rootNode, Unit *unit, const SkillType *skillType) { - //const XmlNode *unitAttackBoostEffectOriginatorNode = rootNode->getChild("UnitAttackBoostEffect"); - const XmlNode *unitAttackBoostEffectOriginatorNode = rootNode; +void UnitAttackBoostEffect::applyLoadedAttackBoostParticles(UnitParticleSystemType *upstPtr,const XmlNode *node, Unit* unit) { + if (upstPtr != NULL) { + bool showUnitParticles = Config::getInstance().getBool("UnitParticles","true"); + if (showUnitParticles == true) { + upst = new UnitParticleSystemType(); + *upst = *upstPtr; + upst->loadGame(node); - AttackBoost *load_boost = new AttackBoost(); - load_boost->loadGame(unitAttackBoostEffectOriginatorNode,unit->getFaction(),skillType); - boost = load_boost; + ups = new UnitParticleSystem(200); + //ups->loadGame(node2); + ups->setParticleOwner(unit); + upst->setValues(ups); + ups->setPos(unit->getCurrVector()); + if (unit->getFaction()->getTexture()) { + ups->setFactionColor(unit->getFaction()->getTexture()->getPixmapConst()->getPixel3f(0, 0)); + } + //printf("Adding attack boost particle to deferred buffer: %p\n",ups); + Renderer::getInstance().addToDeferredParticleSystemList(make_pair(ups, rsGame)); + } + } +} - if(unitAttackBoostEffectOriginatorNode->hasAttribute("source") == true) { - unitId = unitAttackBoostEffectOriginatorNode->getAttribute("source")->getIntValue(); +void UnitAttackBoostEffect::loadGame(const XmlNode *rootNode, Unit *unit, World *world, bool applyToOriginator) { + const XmlNode *unitAttackBoostEffectNode = rootNode; + + if(unitAttackBoostEffectNode->hasAttribute("source") == true) { + unitId = unitAttackBoostEffectNode->getAttribute("source")->getIntValue(); unitPtr = unit; source = unit->getFaction()->findUnit(unitId); + +// printf("#1 Loaded boost effect unitId = %d unitPtr = [%d - %s] source = %p\n", +// unitId,unitPtr->getId(),unitPtr->getType()->getName(false).c_str(),source); } - if(unitAttackBoostEffectOriginatorNode->hasChild("UnitParticleSystemType") == true) { - //const XmlNode *node = unitAttackBoostEffectOriginatorNode->getChild("UnitParticleSystemType"); + // Lets determine the originator unit's attack boost based on the skill used to trigger it + if(unitAttackBoostEffectNode->hasAttribute("source-faction") == true) { + string factionName = unitAttackBoostEffectNode->getAttribute("source-faction")->getValue(); + string unitTypeName = unitAttackBoostEffectNode->getAttribute("source-unit-type")->getValue(); + string skillTypeName = unitAttackBoostEffectNode->getAttribute("source-skill-type")->getValue(); + SkillClass skillClass = static_cast(unitAttackBoostEffectNode->getAttribute("source-skill-class")->getIntValue()); - upst = new UnitParticleSystemType(); - upst->loadGame(unitAttackBoostEffectOriginatorNode); + const UnitType *unitType = world->findUnitTypeByName(factionName, unitTypeName); + if(unitType != NULL) { + const SkillType *skillType = unitType->getSkillType(skillTypeName,skillClass); + if(skillType != NULL) { + boost = skillType->getAttackBoost(); + +// printf("#2 boost effect unitId = %d unitPtr = [%d - %s] source = %p attackBoost src [%p] dest [%p]\n", +// unitId,unitPtr->getId(),unitPtr->getType()->getName(false).c_str(), +// source,boost->unitParticleSystemTypeForSourceUnit,boost->unitParticleSystemTypeForAffectedUnit); + } + } } - if(unitAttackBoostEffectOriginatorNode->hasChild("UnitParticleSystem") == true) { - const XmlNode *node = unitAttackBoostEffectOriginatorNode->getChild("UnitParticleSystem"); + if(boost != NULL) { +// printf("unit [%d - %s] applyToOriginator: %d src [%p] dest [%p] Boost attackBoost->enabled = %d:\n%s\n", +// unit->getId(),unit->getType()->getName(false).c_str(),applyToOriginator,boost->unitParticleSystemTypeForSourceUnit,boost->unitParticleSystemTypeForAffectedUnit,boost->enabled,boost->getDesc(false).c_str()); - ups = new UnitParticleSystem(200); - ups->loadGame(node); - - ups->setParticleOwner(unit); - upst->setValues(ups); - - Renderer::getInstance().addToDeferredParticleSystemList(make_pair(ups, rsGame)); + if(applyToOriginator == true) { + applyLoadedAttackBoostParticles(boost->unitParticleSystemTypeForSourceUnit, + unitAttackBoostEffectNode, unit); + } + else { + applyLoadedAttackBoostParticles(boost->unitParticleSystemTypeForAffectedUnit, + unitAttackBoostEffectNode, unit); + } + } + else { + printf("******!!!! unit [%d - %s] applyToOriginator: %d NO BOOST FOUND!!!\n",unit->getId(),unit->getType()->getName(false).c_str(),applyToOriginator); } } @@ -359,8 +400,13 @@ void UnitAttackBoostEffect::saveGame(XmlNode *rootNode) { boost->saveGame(unitAttackBoostEffectNode); } // const Unit *source; - if(source != NULL) { - unitAttackBoostEffectNode->addAttribute("source",intToStr(source->getId()), mapTagReplacements); + if(getSource() != NULL) { + unitAttackBoostEffectNode->addAttribute("source",intToStr(getSource()->getId()), mapTagReplacements); + + unitAttackBoostEffectNode->addAttribute("source-faction",getSource()->getFaction()->getType()->getName(false), mapTagReplacements); + unitAttackBoostEffectNode->addAttribute("source-unit-type",getSource()->getType()->getName(false), mapTagReplacements); + unitAttackBoostEffectNode->addAttribute("source-skill-type",getSource()->getCurrSkill()->getName(), mapTagReplacements); + unitAttackBoostEffectNode->addAttribute("source-skill-class",intToStr(getSource()->getCurrSkill()->getClass()), mapTagReplacements); } // UnitParticleSystem *ups; if(ups != NULL && Renderer::getInstance().validateParticleSystemStillExists(ups,rsGame) == true) { @@ -383,7 +429,7 @@ UnitAttackBoostEffectOriginator::~UnitAttackBoostEffectOriginator() { currentAppliedEffect = NULL; } -void UnitAttackBoostEffectOriginator::loadGame(const XmlNode *rootNode, Unit *unit) { +void UnitAttackBoostEffectOriginator::loadGame(const XmlNode *rootNode, Unit *unit, World *world) { const XmlNode *unitAttackBoostEffectOriginatorNode = rootNode->getChild("UnitAttackBoostEffectOriginator"); SkillClass skillClass = scStop; @@ -416,7 +462,7 @@ void UnitAttackBoostEffectOriginator::loadGame(const XmlNode *rootNode, Unit *un if(unitAttackBoostEffectOriginatorNode->hasChild("UnitAttackBoostEffect") == true) { currentAppliedEffect = new UnitAttackBoostEffect(); - currentAppliedEffect->loadGame(unitAttackBoostEffectOriginatorNode, unit,this->skillType); + currentAppliedEffect->loadGame(unitAttackBoostEffectOriginatorNode, unit,world, true); } } @@ -2574,6 +2620,7 @@ bool Unit::update() { } } + //printf("Unit has attack boost? unit = [%d - %s] size = %d\n",this->getId(), this->getType()->getName(false).c_str(),(int)currentAttackBoostEffects.size()); for(unsigned int i = 0; i < currentAttackBoostEffects.size(); ++i) { UnitAttackBoostEffect *effect = currentAttackBoostEffects[i]; if(effect != NULL && effect->ups != NULL) { @@ -2582,8 +2629,13 @@ bool Unit::update() { effect->ups->setPos(getCurrVector()); effect->ups->setRotation(getRotation()); } + + //printf("i = %d particleValid = %d\n",i,particleValid); } + //printf("i = %d effect = %p effect->ups = %p\n",i,effect,(effect ? effect->ups : NULL)); } + + if(currentAttackBoostOriginatorEffect.currentAppliedEffect != NULL) { if(currentAttackBoostOriginatorEffect.currentAppliedEffect->ups != NULL) { bool particleValid = Renderer::getInstance().validateParticleSystemStillExists(currentAttackBoostOriginatorEffect.currentAppliedEffect->ups,rsGame); @@ -2693,6 +2745,9 @@ bool Unit::unitHasAttackBoost(const AttackBoost *boost, const Unit *source) { break; } } + + //printf("Unit has attack boost? source = [%d - %s] [%p] boost [%s] result = %d\n",source->getId(), source->getType()->getName(false).c_str(),source,boost->name.c_str(),result); + return result; } @@ -5141,7 +5196,7 @@ Unit * Unit::loadGame(const XmlNode *rootNode, GameSettings *settings, Faction * // UnitAttackBoostEffectOriginator currentAttackBoostOriginatorEffect; // !!! TODO: Softcoder - in progress work to load attack boosts, not working properly yet - //result->currentAttackBoostOriginatorEffect.loadGame(unitNode,result); + result->currentAttackBoostOriginatorEffect.loadGame(unitNode,result, world); // std::vector currentAttackBoostEffects; // for(unsigned int i = 0; i < currentAttackBoostEffects.size(); ++i) { @@ -5150,17 +5205,18 @@ Unit * Unit::loadGame(const XmlNode *rootNode, GameSettings *settings, Faction * // } // !!! TODO: Softcoder - in progress work to load attack boosts, not working properly yet -// if(unitNode->hasChild("UnitAttackBoostEffect") == true) { -// vector unitParticleSystemNodeList = unitNode->getChildList("UnitAttackBoostEffect"); -// for(unsigned int i = 0; i < unitParticleSystemNodeList.size(); ++i) { -// XmlNode *node = unitParticleSystemNodeList[i]; -// -// UnitAttackBoostEffect *attackBoostEffect = new UnitAttackBoostEffect(); -// attackBoostEffect->loadGame(node,result,result->getCurrSkill()); -// -// result->currentAttackBoostEffects.push_back(attackBoostEffect); -// } -// } + if(unitNode->hasChild("UnitAttackBoostEffect") == true) { + vector unitParticleSystemNodeList = unitNode->getChildList("UnitAttackBoostEffect"); + for(unsigned int i = 0; i < unitParticleSystemNodeList.size(); ++i) { + XmlNode *node = unitParticleSystemNodeList[i]; + + UnitAttackBoostEffect *attackBoostEffect = new UnitAttackBoostEffect(); + attackBoostEffect->loadGame(node,result,world,false); + + result->currentAttackBoostEffects.push_back(attackBoostEffect); + } + } + //printf("Unit [%d - %s] has currentAttackBoostEffects count: %d\n",result->getId(),result->getType()->getName(false).c_str(),(int)result->currentAttackBoostEffects.size()); // Mutex *mutexCommands; diff --git a/source/glest_game/type_instances/unit.h b/source/glest_game/type_instances/unit.h index 16877ec4..2adb9b71 100644 --- a/source/glest_game/type_instances/unit.h +++ b/source/glest_game/type_instances/unit.h @@ -300,6 +300,8 @@ private: const Unit *unitPtr; const Unit *source; + + void applyLoadedAttackBoostParticles(UnitParticleSystemType *upstPtr,const XmlNode* node, Unit* unit); public: UnitAttackBoostEffect(); @@ -313,7 +315,7 @@ public: UnitParticleSystemType *upst; virtual void saveGame(XmlNode *rootNode); - virtual void loadGame(const XmlNode *rootNode, Unit *unit, const SkillType *skillType); + virtual void loadGame(const XmlNode *rootNode, Unit *unit, World *world, bool applyToOriginator); }; class UnitAttackBoostEffectOriginator { @@ -327,7 +329,7 @@ public: UnitAttackBoostEffect *currentAppliedEffect; virtual void saveGame(XmlNode *rootNode); - virtual void loadGame(const XmlNode *rootNode, Unit *unit); + virtual void loadGame(const XmlNode *rootNode, Unit *unit, World *world); }; class Unit : public BaseColorPickEntity, ValueCheckerVault, public ParticleOwner { From 2d3e04f4132784571b4f3ed05486c4fda0769876 Mon Sep 17 00:00:00 2001 From: SoftCoder Date: Sun, 22 Dec 2013 21:03:40 -0800 Subject: [PATCH 06/18] - a few more minor code quality fixes --- source/glest_game/types/skill_type.cpp | 6 +++--- source/glest_game/world/map.cpp | 3 --- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/source/glest_game/types/skill_type.cpp b/source/glest_game/types/skill_type.cpp index b71e07aa..be42324a 100644 --- a/source/glest_game/types/skill_type.cpp +++ b/source/glest_game/types/skill_type.cpp @@ -208,8 +208,8 @@ string AttackBoost::getDesc(bool translatedValue) const{ void AttackBoost::loadGame(const XmlNode *rootNode, Faction *faction, const SkillType *skillType) { const XmlNode *attackBoostNode = rootNode->getChild("AttackBoost"); - enabled = attackBoostNode->getAttribute("enabled")->getIntValue(); - allowMultipleBoosts = attackBoostNode->getAttribute("allowMultipleBoosts")->getIntValue(); + enabled = (attackBoostNode->getAttribute("enabled")->getIntValue() != 0); + allowMultipleBoosts = (attackBoostNode->getAttribute("allowMultipleBoosts")->getIntValue() != 0); radius = attackBoostNode->getAttribute("radius")->getIntValue(); targetType = static_cast(attackBoostNode->getAttribute("targetType")->getIntValue()); @@ -234,7 +234,7 @@ void AttackBoost::loadGame(const XmlNode *rootNode, Faction *faction, const Skil unitParticleSystemTypeForAffectedUnit = new UnitParticleSystemType(); unitParticleSystemTypeForAffectedUnit->loadGame(attackBoostNode); - includeSelf = attackBoostNode->getAttribute("includeSelf")->getIntValue(); + includeSelf = (attackBoostNode->getAttribute("includeSelf")->getIntValue() != 0); name = attackBoostNode->getAttribute("name")->getValue(); } diff --git a/source/glest_game/world/map.cpp b/source/glest_game/world/map.cpp index ff5090fd..4c276bfb 100644 --- a/source/glest_game/world/map.cpp +++ b/source/glest_game/world/map.cpp @@ -501,9 +501,6 @@ Checksum Map::load(const string &path, TechTree *techTree, Tileset *tileset) { if(f) fclose(f); } else { - if(f) fclose(f); - f = NULL; - throw megaglest_runtime_error("Can't open file"); } } From 3a24531ba755511bec09546385d2aaddb6755e41 Mon Sep 17 00:00:00 2001 From: SoftCoder Date: Sun, 22 Dec 2013 22:53:26 -0800 Subject: [PATCH 07/18] - more code cleanup based on cppcheck results and valgrind - added -h option to build-mg.sh to show parameter usage. --- build-mg.sh | 14 +- source/glest_game/game/game.cpp | 6 +- source/glest_game/graphics/renderer.cpp | 15 +- source/glest_game/graphics/renderer.h | 2 +- source/glest_game/world/minimap.cpp | 10 +- source/glest_game/world/minimap.h | 2 +- .../include/graphics/gl/texture_gl.h | 2 +- source/shared_lib/include/graphics/pixmap.h | 9 +- source/shared_lib/include/graphics/texture.h | 11 +- .../sources/graphics/gl/texture_gl.cpp | 4 +- source/shared_lib/sources/graphics/model.cpp | 2 +- source/shared_lib/sources/graphics/pixmap.cpp | 137 ++++++++---------- source/shared_lib/sources/miniz/miniz.c | 9 +- 13 files changed, 104 insertions(+), 119 deletions(-) diff --git a/build-mg.sh b/build-mg.sh index cfe8a6b7..54e209f4 100755 --- a/build-mg.sh +++ b/build-mg.sh @@ -18,7 +18,7 @@ CMAKE_ONLY=0 MAKE_ONLY=0 CLANG_FORCED=0 -while getopts "c:m:n:f:" option; do +while getopts "c:m:n:f:h" option; do case "${option}" in c) CPU_COUNT=${OPTARG} @@ -37,6 +37,18 @@ while getopts "c:m:n:f:" option; do CLANG_FORCED=${OPTARG} # echo "${option} value: ${OPTARG}" ;; + h) + echo "Usage: $0