View Single Post
  #7  
Old 02-02-2004, 03:47 PM
smogo
Discordant
 
Join Date: Jan 2004
Location: 47
Posts: 339
Default

Sry if the post was enigmatic.

Lots of the 'rules' are inlined in the code, as integer constants, like :

Code:
// with this formula if you have an attacker with 185 offense skill
        // and a defender with 180 defense, the net effect is
        // 24.05 - 16.2 == 7.85% added
        // an example with the defender having a defense of 85, and the attacker
        // having an offense of 60
        // 7.8 - 7.65 = 0.15% added
        // so basically defense is for cancelling out the attacker's offense,
        // but offense is more effective than defense
        chancetohit += (float)((float)attacker->GetSkill(OFFENSE) * 0.13f);
        chancetohit -= (float)((float)defender->GetSkill(DEFENSE) * 0.09f);

        int16 defender_agi = defender->GetAGI();
        // skill points over 200 are 1/5 as effective
        // at max stat of 252 this is a 10.52% bonus
        defender_agi = (defender_agi <= 200) ? defender_agi : defender_agi + ((d
efender_agi-200)/5);
        chancetohit -= (float)((float)defender_agi * 0.05f);

        // etc ...

could turn into :

in a foo.h :
Code:
#define TOHIT_AttackerSkillFactor  0.13f
#define TOHIT_DefenderSkillFactor  0.09f
// with this formula if you have an attacker with 185 offense skill
        // and a defender with 180 defense, the net effect is
        // 24.05 - 16.2 == 7.85% added
        // an example with the defender having a defense of 85, and the attacker
        // having an offense of 60
        // 7.8 - 7.65 = 0.15% added
        // so basically defense is for cancelling out the attacker's offense,
        // but offense is more effective than defense
#define TOHIT_Base(attacker,defender) ((float)((float)attacker->GetSkill(OFFENSE)* \
					  TOHIT_AttackerSkillFactor  - \
					(float)((float)defender->GetSkill(DEFENSE) \
					 * TOHIT_DefenderSkillFactor  )

// skill points over 200 are 1/5 as effective
// at max stat of 252 this is a 10.52% bonus
#define TOHIT_DefenderAgiCap 200
#define TOHIT_DefenderAgiCappedRaise 0.2f
#define TOHIT_DefenderAgiCapped(defagi)   (defagi < TOHIT_DefenderAgiCap \
						? defagi \
                                                : (defagi - TOHIT_DefenderAgiCap) * TOHIT_DefAgiCappedRaise ))

#define TOHIT_DefenderAgiModifierFactor 0.05f
#define TOHIT_DefenderAgiModifier(defender) \
	 (float)(TOHIT_DefenderAgiCapped(defender->GetAGI())*TOHIT_DefenderAgiModifierFactor))
then attack.cpp
Code:
	// ...
        
        // base attack vs defense skills
	chancetohit =TOHIT_Base(attacker,defender)

        // apply defender's agility
        chancetohit -= TOHIT_DefenderAgiModifier(defender);
obviously the names are not good, as TOHit_Base doesn't explain a thing, and TOHIT_DefenderAgiModifierFactor is way too long. And the change is not complete.

But this could be the first step to :
- group 'rules' in a single source file, leaving only the logic in attack.cpp , and make it more readable.
- easily change a rule through edit of the foo.h
- move 'rules' to database driven, like :
Code:
// in foo.h
extern float gamesvars[];

#define TOHIT_DefenderAgiCap \
               gamesvars[VAR_TOHIT_DefenderAgiCap]
I guess it did not tell you anything new. It's just that i had been surprised to see all these numbers in engine code. It would be very fine if game could be tuned from the DB.
Reply With Quote