diff --git a/data/glest_game b/data/glest_game index 1503ca70..3de3304f 160000 --- a/data/glest_game +++ b/data/glest_game @@ -1 +1 @@ -Subproject commit 1503ca70fd0813c5fd090aef2b024e04bb1c3161 +Subproject commit 3de3304fd08fed556c5bfee168fcaa64bbf75612 diff --git a/source/.gitignore b/source/.gitignore index 74175717..408dc5b7 100644 --- a/source/.gitignore +++ b/source/.gitignore @@ -1,3 +1,4 @@ /windows_deps*/ /glest_game/facilities/gitversion.h -/glest_game/site/ \ No newline at end of file +/glest_game/site/ +/Debug diff --git a/source/g3d_viewer/main.cpp b/source/g3d_viewer/main.cpp index 1276f73e..98ad3d2a 100644 --- a/source/g3d_viewer/main.cpp +++ b/source/g3d_viewer/main.cpp @@ -1371,6 +1371,8 @@ void MainWindow::loadParticle(string path) { for(std::vector::const_iterator it= unitParticleSystemTypes.begin(); it != unitParticleSystemTypes.end(); ++it) { UnitParticleSystem *ups= new UnitParticleSystem(200); + + ups->setParticleType((*it)); (*it)->setValues(ups); if(size > 0) { //getCurrVectorFlat() + Vec3f(0.f, type->getHeight()/2.f, 0.f); diff --git a/source/glest_game/graphics/particle_type.cpp b/source/glest_game/graphics/particle_type.cpp index 5c6e67f0..e96ed9f8 100644 --- a/source/glest_game/graphics/particle_type.cpp +++ b/source/glest_game/graphics/particle_type.cpp @@ -305,6 +305,7 @@ void ParticleSystemType::setValues(AttackParticleSystem *ats){ for(Children::iterator i=children.begin(); i!=children.end(); ++i){ UnitParticleSystem *child = new UnitParticleSystem(); child->setParticleOwner(ats->getParticleOwner()); + child->setParticleType((*i)); (*i)->setValues(child); ats->addChild(child); child->setState(ParticleSystem::sPlay); diff --git a/source/glest_game/graphics/particle_type.h b/source/glest_game/graphics/particle_type.h index 6373e792..0291cbbf 100644 --- a/source/glest_game/graphics/particle_type.h +++ b/source/glest_game/graphics/particle_type.h @@ -52,7 +52,7 @@ class UnitParticleSystemType; /// A type of particle system // =========================================================== -class ParticleSystemType { +class ParticleSystemType : public ParticleSystemTypeInterface { protected: string type; Texture2D *texture; diff --git a/source/glest_game/graphics/unit_particle_type.cpp b/source/glest_game/graphics/unit_particle_type.cpp index f90cf44e..0deeefd3 100644 --- a/source/glest_game/graphics/unit_particle_type.cpp +++ b/source/glest_game/graphics/unit_particle_type.cpp @@ -218,6 +218,7 @@ const void UnitParticleSystemType::setValues(UnitParticleSystem *ups){ for(Children::iterator i=children.begin(); i!=children.end(); ++i){ UnitParticleSystem *child = new UnitParticleSystem(); child->setParticleOwner(ups->getParticleOwner()); + child->setParticleType((*i)); (*i)->setValues(child); ups->addChild(child); } diff --git a/source/glest_game/type_instances/object.cpp b/source/glest_game/type_instances/object.cpp index 4bafffb7..29b565b0 100644 --- a/source/glest_game/type_instances/object.cpp +++ b/source/glest_game/type_instances/object.cpp @@ -113,6 +113,7 @@ void Object::initParticlesFromTypes(const ModelParticleSystemTypes *particleType for(ObjectParticleSystemTypes::const_iterator it= particleTypes->begin(); it != particleTypes->end(); ++it){ UnitParticleSystem *ups= new UnitParticleSystem(200); ups->setParticleOwner(this); + ups->setParticleType((*it)); (*it)->setValues(ups); ups->setPos(this->pos); ups->setRotation(this->rotation); diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index 953887ce..eda14d39 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -331,6 +331,8 @@ void UnitAttackBoostEffect::applyLoadedAttackBoostParticles(UnitParticleSystemTy ups = new UnitParticleSystem(200); //ups->loadGame(node2); ups->setParticleOwner(unit); + ups->setParticleType(upst); + upst->setValues(ups); ups->setPos(unit->getCurrVector()); ups->setRotation(unit->getRotation()); @@ -1291,12 +1293,16 @@ void Unit::setCurrSkill(const SkillType *currSkill) { unitParticleSystems.empty() == true) { //printf("START - particle system type\n"); - for(UnitParticleSystemTypes::const_iterator it= currSkill->unitParticleSystemTypes.begin(); it != currSkill->unitParticleSystemTypes.end(); ++it) { + /* + for(UnitParticleSystemTypes::const_iterator it= currSkill->unitParticleSystemTypes.begin(); + it != currSkill->unitParticleSystemTypes.end(); ++it) { if((*it)->getStartTime() == 0.0) { //printf("Adding NON-queued particle system type [%s] [%f] [%f]\n",(*it)->getType().c_str(),(*it)->getStartTime(),(*it)->getEndTime()); UnitParticleSystem *ups = new UnitParticleSystem(200); ups->setParticleOwner(this); + ups->setParticleType((*it)); + (*it)->setValues(ups); ups->setPos(getCurrVector()); ups->setRotation(getRotation()); @@ -1313,6 +1319,9 @@ void Unit::setCurrSkill(const SkillType *currSkill) { queuedUnitParticleSystemTypes.push_back(*it); } } + */ + checkCustomizedUnitParticleListTriggers(unitParticleSystems, + currSkill->unitParticleSystemTypes,queuedUnitParticleSystemTypes); } progress2= 0; if(this->currSkill != currSkill) { @@ -2396,6 +2405,8 @@ void Unit::updateAttackBoostProgress(const Game* game) { currentAttackBoostOriginatorEffect.currentAppliedEffect->ups = new UnitParticleSystem(200); currentAttackBoostOriginatorEffect.currentAppliedEffect->ups->setParticleOwner(this); + currentAttackBoostOriginatorEffect.currentAppliedEffect->ups->setParticleType(currentAttackBoostOriginatorEffect.currentAppliedEffect->upst); + currentAttackBoostOriginatorEffect.currentAppliedEffect->upst->setValues( currentAttackBoostOriginatorEffect.currentAppliedEffect->ups); currentAttackBoostOriginatorEffect.currentAppliedEffect->ups->setPos( @@ -2507,6 +2518,8 @@ void Unit::updateAttackBoostProgress(const Game* game) { currentAttackBoostOriginatorEffect.currentAppliedEffect->ups = new UnitParticleSystem(200); currentAttackBoostOriginatorEffect.currentAppliedEffect->ups->setParticleOwner(this); + currentAttackBoostOriginatorEffect.currentAppliedEffect->ups->setParticleType(currentAttackBoostOriginatorEffect.currentAppliedEffect->upst); + currentAttackBoostOriginatorEffect.currentAppliedEffect->upst->setValues( currentAttackBoostOriginatorEffect.currentAppliedEffect->ups); currentAttackBoostOriginatorEffect.currentAppliedEffect->ups->setPos( @@ -2786,6 +2799,8 @@ void Unit::updateTimedParticles() { UnitParticleSystem *ups = new UnitParticleSystem(200); ups->setParticleOwner(this); + ups->setParticleType(pst); + pst->setValues(ups); ups->setPos(getCurrVector()); ups->setRotation(getRotation()); @@ -2927,6 +2942,8 @@ bool Unit::applyAttackBoost(const AttackBoost *boost, const Unit *source) { effect->ups = new UnitParticleSystem(200); effect->ups->setParticleOwner(this); + effect->ups->setParticleType(effect->upst); + effect->upst->setValues(effect->ups); effect->ups->setPos(getCurrVector()); effect->ups->setRotation(getRotation()); @@ -3977,8 +3994,131 @@ void Unit::stopDamageParticles(bool force) { checkCustomizedParticleTriggers(force); } +void Unit::checkCustomizedUnitParticleListTriggers(vector &unitParticleSystemsList, + const UnitParticleSystemTypes &unitParticleSystemTypesList, + vector &queuedUnitParticleSystemTypesList) { + if(showUnitParticles == true) { + vector systemTypesInUse; + + if(unitParticleSystemsList.empty() == false) { + for(int index = (int)unitParticleSystemsList.size() - 1; index >= 0; index--) { + UnitParticleSystem *ps = unitParticleSystemsList[index]; + if(ps != NULL) { + if(Renderer::getInstance().validateParticleSystemStillExists(ps,rsGame) == true) { + + bool stopParticle = false; + if((ps->getParticleType() != NULL && + ps->getParticleType()->getMinmaxEnabled())) { + + if(ps->getParticleType() != NULL) { + if(ps->getParticleType()->getMinmaxIsPercent() == false) { + if(hp < ps->getParticleType()->getMinHp() || hp > ps->getParticleType()->getMaxHp()) { + stopParticle = true; + + //printf("STOP Particle line: %d\n",__LINE__); + } + } + else { + int hpPercent = (hp / type->getTotalMaxHp(&totalUpgrade) * 100); + if(hpPercent < ps->getParticleType()->getMinHp() || hpPercent > ps->getParticleType()->getMaxHp()) { + stopParticle = true; + + //printf("STOP Particle line: %d\n",__LINE__); + } + } + } + + if(stopParticle == true) { + ps->fade(); + unitParticleSystemsList.erase(unitParticleSystemsList.begin() + index); + } + } + + if(ps->getParticleType() != NULL && stopParticle == false) { + systemTypesInUse.push_back(ps->getParticleType()); + } + } + } + } + } + + //printf("Check Particle start line: %d size: %d\n",__LINE__,(int)unitParticleSystemTypesList.size()); + + if(unitParticleSystemTypesList.empty() == false) { + + //for(unsigned int index = 0; index < unitParticleSystemTypesList.size(); ++index) { + for(UnitParticleSystemTypes::const_iterator iterParticleType = unitParticleSystemTypesList.begin(); + iterParticleType != unitParticleSystemTypesList.end(); ++iterParticleType) { + UnitParticleSystemType *pst = *iterParticleType; + + vector::iterator iterFind = std::find(systemTypesInUse.begin(),systemTypesInUse.end(),pst); + + //printf("Check Particle line: %d isenabled: %d already in use: %d\n",__LINE__,pst->getMinmaxEnabled(),(iterFind == systemTypesInUse.end())); + + if(pst->getMinmaxEnabled() == true) { + + //printf("Check Particle line: %d isenabled: %d already in use: %d\n",__LINE__,pst->getMinmaxEnabled(),(iterFind != systemTypesInUse.end())); + + if(iterFind == systemTypesInUse.end()) { + bool showParticle = false; + if(pst->getMinmaxIsPercent() == false) { + if(hp >= pst->getMinHp() && hp <= pst->getMaxHp()) { + showParticle = true; + + //printf("START Particle line: %d\n",__LINE__); + } + } + else { + int hpPercent = (hp / type->getTotalMaxHp(&totalUpgrade) * 100); + if(hpPercent >= pst->getMinHp() && hpPercent <= pst->getMaxHp()) { + showParticle = true; + + //printf("START Particle line: %d\n",__LINE__); + } + } + + if(showParticle == true) { + + if(pst->getStartTime() == 0.0) { + UnitParticleSystem *ups = new UnitParticleSystem(200); + ups->setParticleOwner(this); + ups->setParticleType(pst); + + pst->setValues(ups); + ups->setPos(getCurrVector()); + ups->setRotation(getRotation()); + ups->setUnitModel(getCurrentModelPtr()); + if(getFaction()->getTexture()) { + ups->setFactionColor(getFaction()->getTexture()->getPixmapConst()->getPixel3f(0,0)); + } + unitParticleSystemsList.push_back(ups); + Renderer::getInstance().manageParticleSystem(ups, rsGame); + } + else { + queuedUnitParticleSystemTypesList.push_back(pst); + } + } + } + } + } + } + } + +} + +void Unit::checkCustomizedUnitParticleTriggers() { + if(currSkill != NULL) { + checkCustomizedUnitParticleListTriggers(unitParticleSystems, + currSkill->unitParticleSystemTypes,queuedUnitParticleSystemTypes); + } +} + void Unit::checkCustomizedParticleTriggers(bool force) { - // Now check if we have special hp triggered particles + // + // Now check if we have special pre-exisitng hp triggered particles and + // end those that should no longer display + // + // end s particles if(damageParticleSystems.empty() == false) { for(int i = (int)damageParticleSystems.size()-1; i >= 0; --i) { UnitParticleSystem *ps = damageParticleSystems[i]; @@ -4028,7 +4168,9 @@ void Unit::checkCustomizedParticleTriggers(bool force) { } } - // Now check if we have special hp triggered particles + // + // Now check if we have new special hp triggered particles to display + // //start additional particles if(showUnitParticles && type->damageParticleSystemTypes.empty() == false && @@ -4057,6 +4199,8 @@ void Unit::checkCustomizedParticleTriggers(bool force) { UnitParticleSystem *ups = new UnitParticleSystem(200); ups->setParticleOwner(this); + ups->setParticleType(pst); + pst->setValues(ups); ups->setPos(getCurrVector()); ups->setRotation(getRotation()); @@ -4071,6 +4215,8 @@ void Unit::checkCustomizedParticleTriggers(bool force) { } } } + + checkCustomizedUnitParticleTriggers(); } void Unit::startDamageParticles() { @@ -4084,6 +4230,8 @@ void Unit::startDamageParticles() { if(pst->getMinmaxEnabled() == false && damageParticleSystemsInUse.find(i) == damageParticleSystemsInUse.end()) { UnitParticleSystem *ups = new UnitParticleSystem(200); ups->setParticleOwner(this); + ups->setParticleType(pst); + pst->setValues(ups); ups->setPos(getCurrVector()); ups->setRotation(getRotation()); diff --git a/source/glest_game/type_instances/unit.h b/source/glest_game/type_instances/unit.h index bbbfa12d..64cc1d4d 100644 --- a/source/glest_game/type_instances/unit.h +++ b/source/glest_game/type_instances/unit.h @@ -821,7 +821,14 @@ private: void startDamageParticles(); uint32 getFrameCount() const; + void checkCustomizedParticleTriggers(bool force); + void checkCustomizedUnitParticleTriggers(); + void checkCustomizedUnitParticleListTriggers(vector &unitParticleSystemsList, + const UnitParticleSystemTypes &unitParticleSystemTypesList, + vector &queuedUnitParticleSystemTypesList); + + bool checkModelStateInfoForNewHpValue(); void checkUnitLevel(); diff --git a/source/glest_game/types/skill_type.cpp b/source/glest_game/types/skill_type.cpp index 90d3f782..6b055c30 100644 --- a/source/glest_game/types/skill_type.cpp +++ b/source/glest_game/types/skill_type.cpp @@ -533,9 +533,21 @@ void SkillType::load(const XmlNode *sn, const XmlNode *attackBoostsNode, unitParticleSystemType->setEndTime(particleNode->getAttribute("end-time")->getFloatValue()); } + if(particleNode->getChild(i)->hasAttribute("minHp") && particleNode->getChild(i)->hasAttribute("maxHp")) { + unitParticleSystemType->setMinmaxEnabled(true); + unitParticleSystemType->setMinHp(particleNode->getChild(i)->getAttribute("minHp")->getIntValue()); + unitParticleSystemType->setMaxHp(particleNode->getChild(i)->getAttribute("maxHp")->getIntValue()); + + if(particleNode->getChild(i)->hasAttribute("ispercentbased")) { + unitParticleSystemType->setMinmaxIsPercent(particleNode->getChild(i)->getAttribute("ispercentbased")->getBoolValue()); + } + } + loadedFileList[currentPath + path].push_back(make_pair(parentLoader,particleFileNode->getAttribute("path")->getRestrictedValue())); unitParticleSystemTypes.push_back(unitParticleSystemType); } + + //printf("Load skill particles line: %d size: %d\n",__LINE__,(int)unitParticleSystemTypes.size()); } } diff --git a/source/shared_lib/include/graphics/particle.h b/source/shared_lib/include/graphics/particle.h index 78607888..a7d9fff5 100644 --- a/source/shared_lib/include/graphics/particle.h +++ b/source/shared_lib/include/graphics/particle.h @@ -58,6 +58,7 @@ public: public: Particle() { + speedUpRelative = 0; size = 0; energy = 0; } @@ -93,6 +94,20 @@ public: virtual void logParticleInfo(string info)= 0; }; + +class ParticleSystemTypeInterface { +public: + + ParticleSystemTypeInterface() {}; + virtual ~ParticleSystemTypeInterface() {}; + + virtual bool getMinmaxEnabled() const = 0; + virtual int getMinHp() const = 0; + virtual int getMaxHp() const = 0; + virtual bool getMinmaxIsPercent() const = 0; + +}; + // ===================================================== // class ParticleSystem // ===================================================== @@ -344,12 +359,15 @@ private: float startTime; float endTime; + ParticleSystemTypeInterface *particleSystemType; + public: enum Shape{ sLinear, // generated in a sphere, flying in direction sSpherical, // generated in a sphere, flying away from center sConical, // generated in a cone at angle from direction }; + bool relative; bool relativeDirection; bool fixed; @@ -376,6 +394,13 @@ public: virtual ParticleSystemType getParticleSystemType() const { return pst_UnitParticleSystem;} + ParticleSystemTypeInterface * getParticleType() const { + return particleSystemType; + } + void setParticleType(ParticleSystemTypeInterface *type) { + particleSystemType = type; + } + //virtual virtual void initParticle(Particle *p, int particleIndex); virtual void updateParticle(Particle *p); diff --git a/source/shared_lib/sources/graphics/particle.cpp b/source/shared_lib/sources/graphics/particle.cpp index 9e69bcd3..36d9334d 100644 --- a/source/shared_lib/sources/graphics/particle.cpp +++ b/source/shared_lib/sources/graphics/particle.cpp @@ -1009,6 +1009,8 @@ Vec3f UnitParticleSystem::lightColor=Vec3f(1.0f,1.0f,1.0f); UnitParticleSystem::UnitParticleSystem(int particleCount) : GameParticleSystem(particleCount), parent(NULL) { + + particleSystemType = NULL; radius= 0.5f; speed= 0.01f; windSpeed= Vec3f(0.0f);