damagePercent for projectiles

all given damage percents from the projectiles must sum up to exactly 100%
This commit is contained in:
titiger 2014-07-20 22:47:07 +02:00
parent da23e4c048
commit 7e81728fe8
5 changed files with 25 additions and 10 deletions

View File

@ -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();

View File

@ -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;}

View File

@ -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<XmlNode *> 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()){

View File

@ -2501,10 +2501,10 @@ void UnitUpdater::updateSwitchTeam(Unit *unit, int frameIndex) {
// ==================== attack ====================
void UnitUpdater::hit(Unit *attacker){
hit(attacker, dynamic_cast<const AttackSkillType*>(attacker->getCurrSkill()), attacker->getTargetPos(), attacker->getTargetField());
hit(attacker, dynamic_cast<const AttackSkillType*>(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<float>(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<float>(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());

View File

@ -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