From 7e81728fe8cc3a2db63fb62305a452013e189130 Mon Sep 17 00:00:00 2001 From: titiger Date: Sun, 20 Jul 2014 22:47:07 +0200 Subject: [PATCH] damagePercent for projectiles all given damage percents from the projectiles must sum up to exactly 100% --- source/glest_game/types/projectile_type.cpp | 6 +++++- source/glest_game/types/projectile_type.h | 3 +++ source/glest_game/types/skill_type.cpp | 9 ++++++++- source/glest_game/world/unit_updater.cpp | 13 +++++++------ source/glest_game/world/unit_updater.h | 4 ++-- 5 files changed, 25 insertions(+), 10 deletions(-) diff --git a/source/glest_game/types/projectile_type.cpp b/source/glest_game/types/projectile_type.cpp index 3e1607c3..fb10075e 100644 --- a/source/glest_game/types/projectile_type.cpp +++ b/source/glest_game/types/projectile_type.cpp @@ -31,7 +31,7 @@ ProjectileType::ProjectileType() { shakeVisible=true; shakeInCameraView=true; shakeCameraDistanceAffected=false; - + damagePercentage=100; } ProjectileType::~ProjectileType() { @@ -56,6 +56,10 @@ void ProjectileType::load(const XmlNode *projectileNode, const string &dir, cons attackStartTime=0.0f; } + // damage percentage MUST be set! + damagePercentage =projectileNode->getAttribute("damage-percentage")->getIntValue(); + + // projectiles MUST have a particle system. const XmlNode *particleNode= projectileNode->getChild("particle"); string path= particleNode->getAttribute("path")->getRestrictedValue(); diff --git a/source/glest_game/types/projectile_type.h b/source/glest_game/types/projectile_type.h index 113ae607..27aaeb48 100644 --- a/source/glest_game/types/projectile_type.h +++ b/source/glest_game/types/projectile_type.h @@ -48,6 +48,7 @@ protected: bool shakeVisible; bool shakeInCameraView; bool shakeCameraDistanceAffected; + int damagePercentage; public: ProjectileType(); @@ -69,6 +70,8 @@ public: bool isShakeInCameraView() const{return shakeInCameraView;} int getShakeIntensity() const{return shakeIntensity;} bool isShakeVisible() const{return shakeVisible;} + int getDamagePercentage() const {return damagePercentage;} + void setDamagePercentage(int value) {damagePercentage=value;} void setProjectileParticleSystemType(ParticleSystemTypeProjectile *pointer) {projectileParticleSystemType=pointer;} ParticleSystemTypeProjectile* getProjectileParticleSystemType() {return projectileParticleSystemType;} diff --git a/source/glest_game/types/skill_type.cpp b/source/glest_game/types/skill_type.cpp index a9832c3a..f7a13a31 100644 --- a/source/glest_game/types/skill_type.cpp +++ b/source/glest_game/types/skill_type.cpp @@ -910,6 +910,7 @@ void AttackSkillType::load(const XmlNode *sn, const XmlNode *attackBoostsNode, ProjectileType *projectileType=new ProjectileType(); projectileTypes.push_back(projectileType); projectileType->setAttackStartTime(attackStartTime); + projectileType->setDamagePercentage(100); //proj particle if(projectileNode->hasChild("particle")){ const XmlNode *particleNode= projectileNode->getChild("particle"); @@ -945,14 +946,20 @@ void AttackSkillType::load(const XmlNode *sn, const XmlNode *attackBoostsNode, else { const XmlNode *projectilesNode= sn->getChild("projectiles"); vector projectilesNodeList = projectilesNode->getChildList("projectile"); + int totalDamagePercentage=0; for(unsigned int i = 0; i < projectilesNodeList.size(); ++i) { const XmlNode *projectileNode= projectilesNodeList[i]; ProjectileType *projectileType=new ProjectileType(); projectileType->load(projectileNode,dir, tt->getPath(), loadedFileList, parentLoader); - + totalDamagePercentage += projectileType->getDamagePercentage(); projectileTypes.push_back(projectileType); projectile=true; } + + if(totalDamagePercentage!=100){ + throw megaglest_runtime_error("Damages percentages of projectiles don't sum up to 100 %"); + } + //general hit sounds, individual ones can be set in projectiles const XmlNode *soundNode= sn->getChild("hitsound"); if(soundNode->getAttribute("enabled")->getBoolValue()){ diff --git a/source/glest_game/world/unit_updater.cpp b/source/glest_game/world/unit_updater.cpp index 90835e11..d1ea979b 100644 --- a/source/glest_game/world/unit_updater.cpp +++ b/source/glest_game/world/unit_updater.cpp @@ -2501,10 +2501,10 @@ void UnitUpdater::updateSwitchTeam(Unit *unit, int frameIndex) { // ==================== attack ==================== void UnitUpdater::hit(Unit *attacker){ - hit(attacker, dynamic_cast(attacker->getCurrSkill()), attacker->getTargetPos(), attacker->getTargetField()); + hit(attacker, dynamic_cast(attacker->getCurrSkill()), attacker->getTargetPos(), attacker->getTargetField(),100); } -void UnitUpdater::hit(Unit *attacker, const AttackSkillType* ast, const Vec2i &targetPos, Field targetField){ +void UnitUpdater::hit(Unit *attacker, const AttackSkillType* ast, const Vec2i &targetPos, Field targetField, int damagePercent){ //hit attack positions if(ast != NULL && ast->getSplash()) { char szBuf[8096]=""; @@ -2524,7 +2524,7 @@ void UnitUpdater::hit(Unit *attacker, const AttackSkillType* ast, const Vec2i &t float distance = pci.getPos().dist(targetPos); distance = truncateDecimal(distance,6); - damage(attacker, ast, attacked, distance); + damage(attacker, ast, attacked, distance,damagePercent); } } } @@ -2537,12 +2537,12 @@ void UnitUpdater::hit(Unit *attacker, const AttackSkillType* ast, const Vec2i &t attacker->addNetworkCRCDecHp(szBuf); if(attacked != NULL) { - damage(attacker, ast, attacked, 0.f); + damage(attacker, ast, attacked, 0.f,damagePercent); } } } -void UnitUpdater::damage(Unit *attacker, const AttackSkillType* ast, Unit *attacked, float distance) { +void UnitUpdater::damage(Unit *attacker, const AttackSkillType* ast, Unit *attacked, float distance, int damagePercent) { if(attacker == NULL) { throw megaglest_runtime_error("attacker == NULL"); } @@ -2568,6 +2568,7 @@ void UnitUpdater::damage(Unit *attacker, const AttackSkillType* ast, Unit *attac damage *= damageMultiplier; damage = truncateDecimal(damage,6); + damage = (damage*damagePercent)/100; if(damage < 1) { damage= 1; } @@ -3249,7 +3250,7 @@ void ParticleDamager::update(ParticleSystem *particleSystem) { snprintf(szBuf,8095,"Unit hitting [ParticleDamager::update] [%s] targetField = %d",targetPos.getString().c_str(),targetField); attacker->addNetworkCRCDecHp(szBuf); - unitUpdater->hit(attacker, ast, targetPos, targetField); + unitUpdater->hit(attacker, ast, targetPos, targetField, projectileType->getDamagePercentage()); //char szBuf[8096]=""; //snprintf(szBuf,8095,"ParticleDamager::update attacker particleSystem before: %s\nafter: %s",auditBeforeHit.c_str(),particleSystem->toString().c_str()); diff --git a/source/glest_game/world/unit_updater.h b/source/glest_game/world/unit_updater.h index 6c98dbeb..b40060fd 100644 --- a/source/glest_game/world/unit_updater.h +++ b/source/glest_game/world/unit_updater.h @@ -141,8 +141,8 @@ public: private: //attack void hit(Unit *attacker); - void hit(Unit *attacker, const AttackSkillType* ast, const Vec2i &targetPos, Field targetField); - void damage(Unit *attacker, const AttackSkillType* ast, Unit *attacked, float distance); + void hit(Unit *attacker, const AttackSkillType* ast, const Vec2i &targetPos, Field targetField, int damagePercent); + void damage(Unit *attacker, const AttackSkillType* ast, Unit *attacked, float distance, int damagePercent); void startAttackParticleSystem(Unit *unit, float lastAnimProgress, float animProgress); //misc