Thread: Combat Fixes
View Single Post
  #24  
Old 10-08-2008, 03:20 PM
James76
Sarnak
 
Join Date: Sep 2008
Location: Canada
Posts: 53
Smile

Alrighty, I've made two lists of changes, one for the combat fixes, and one for the generic type warnings and general use of code. The file link I posted above included all of them, I don't believe I missed anything although I may have, and you will notice them when you compile. That is, you shouldn't get any warnings anymore when you execute 'make' for the zone executable, if all other ".o" files were already made except attack.o. To anyone who doesn't already know, after you "make zone", delete attack.o, and run make again -- that is what I'm talking about. My posted file link also included a uniform formatting scheme, making the file 500% more readable. Some of the code in the original file had skewed blocks which made tracing slightly difficult. One of the companies I worked for had issued to us a uniform coding methodology document which I've been applying ever since, which made all projects readable by everyone so there wasn't ever any confusion. You will also notice that the new variables I create include a type-hint in its name, which was also part of that referred document.

To address Trevius' statement about being a relatively new member, I had been following this project for some time, though I haven't put my mind towards applying changes. It wasn't until I basically quit all MMO's and I remembered this old project, and I came back to see how far it came, and started up my own server for development. I have been coding C++ specifically for about 20 years, and I have a knack for code that allows me to just jump in on any project, because its clearer to me than reading english. This project only uses perhaps 20-30% of the potential of C++, according to Strustrup's own definitive language guide. It can get 1000% more confusing when you see all that is possible, and even then its readable to me with no issues at all. I have always had this gift, if you would like to call it that, ever since I started coding when I was 6 years old on an IBM XT in BASIC. I knew how to code before learning how to read, I don't know how or why, its just always been natural. Maybe I learned how to read by using those "learn to program BASIC" manuals with those type-them-in starter programs. But for certain, I understood math functions like ABS(), exponents, and BEDMAS when they were teaching the other kids Addition. When I was 7 I traced the source code of a learning game called Lemonade Stand, to remove the ABS() from an input line when you buy your components, during a class break on a Commodore PET, so that you could buy & sell like it was a free market. My teacher was most definitely NOT impressed when I showed I could make millions, because she saw it like an act of destroying school property, even though the change was not permanent in any way.... But I digress.

All these changes refer to an unedited attack.cpp from build 1129. I'll give the line number (or range) with a colon, and the required change. Sometimes I'll include an unchanged first line of a multi-line modification.

You may want to work from the bottom-up, so as not to become confused by line-number skewing, and preferably from the very bottom of this entire post.

Ok, the riposte fix, and some combat math fixes are as follows:
Code:
342:
  if (damage >= 0 && CanThisClassRiposte() && !other->BehindMob(this, other->GetX(), other->GetY()))


956-969:
  int nBonus = 0;
  int nLevel = GetLevel();

  if(GetClass() == MONK)
    nBonus += 20;
  if(nLevel > 50)
    nBonus += 15 * ((nLevel - 45)/5);
    
  float fBonus = 1.0f + static_cast<float>(nBonus)/100.0f;
  min_hit = static_cast<int>(static_cast<float>(min_hit) * fBonus);
  max_hit = static_cast<int>(static_cast<float>(max_hit) * fBonus);


978:
    min_hit = static_cast<int>(static_cast<float>(min_hit) * static_cast<float>(100 + itembonuses.MinDamageModifier + spellbonuses.MinDamageModifier) / 100.0f);


995:
  other->AddToHateList(this, 0);
  other->AvoidDamage(this, damage);


1526:
  damage = 0;  //miss
  other->AvoidDamage(this, damage);


OK, now for the type warning fixes, as well as the "++" or "--" modifications. These type fixes are not some sort of psychotic application of static_cast, it was only applied to replace the older "C" type-cast ing of (int) with static_cast(int), or because the math led me to believe (with careful analysis) a cast may or should be required. You will notice I did not type-cast everything, which would be a mark of insanity, because the compiler -will- apply casts when risk of loss of information is nil, without warning. For example, an int to a float is no risk, and no casting required.

Code:
LINE 174 & 175:
  chancetohit += static_cast<int>(145.0f * static_cast<float>(level_difference) / 100.0f);
  chancetohit -= static_cast<int>(static_cast<float>(defender->GetAGI()) * 0.015f);

347:
  bonus += 2.0f + static_cast<float>(skill)/35.0f + static_cast<float>(GetDEX())/200.0f;

364:
  bonus = 2.0f + static_cast<float>(skill)/35.0f + static_cast<float>(GetDEX())/200.0f;

383:
  bonus = static_cast<float>(defender->spellbonuses.ParryChance + defender->itembonuses.ParryChance) / 100.0f;

385:
  bonus += 2.0f + static_cast<float>(skill)/35.0 + static_cast<float>(GetDEX())/200.0f;

405:
  bonus = static_cast<float>(defender->spellbonuses.DodgeChance + defender->itembonuses.DodgeChance) / 100.0f;

407:
  bonus += 2.0f + static_cast<float>(skill)/35.0f + static_cast<float>(GetAGI())/200.0f;

477:
  uint32 intervalsAllowed = 20;

517:
  acfail = static_cast<int>(atof(tmp) * 100.0f);

532:
  acrandom = static_cast<int>((atof(tmp)+1.0f) * 100.0f);

537:
  damage -= static_cast<int>(GetAC() * acreduction/100.0f);

633:
  if(weapon_item->BaneDmgBody == static_cast<uint32>(against->GetBodyType())){

650:
  if(weapon_item->BaneDmgBody == static_cast<uint32>(against->GetBodyType())){

706:
  for(int x = 0; x < 5; ++x){

738:
  for(int x = 0; x < 5; ++x){

767:
  dmg += static_cast<int>(eledmg * against->ResistSpell(weapon_item->GetItem()->ElemDmgType, 0, this) / 100);

771:
  for(int x = 0; x < 5; ++x){

775:
  dmg += static_cast<int>(weapon_item->GetAugment(x)->GetItem()->ElemDmgAmt * against->ResistSpell(weapon_item->GetAugment(x)->GetItem()->ElemDmgType, 0, this) / 100);

783:
  if(weapon_item->GetItem()->BaneDmgBody == static_cast<uint32>(against->GetBodyType())){

801:
  for(int x = 0; x < 5; ++x){

803:
  if(weapon_item->GetAugment(x)->GetItem()->BaneDmgBody == static_cast<uint32>(against->GetBodyType())){

822:
  if(weapon_item->GetItem()->BaneDmgBody == static_cast<uint32>(against->GetBodyType())){

840:
  for(int x = 0; x < 5; ++x){

922:
  //int8 otherlevel = other->GetLevel() ? other->GetLevel() : 1; //unused

932:
  weapon_damage = static_cast<int>(static_cast<float>(weapon_damage) * (100.0f+static_cast<float>(bonus) / 100.0f));

1473:
  if(weapon->BaneDmgBody == static_cast<uint32>(other->GetBodyType())){

1482:
  eleBane += static_cast<int16>(weapon->ElemDmgAmt * other->ResistSpell(weapon->ElemDmgType, 0, this) / 100);

1724:
  for (uint32 i = 0; i < MAX_GROUP_MEMBERS; ++i){

1766:
  for(int i=0;i<6;++i) { // Doesnt work right, needs work

2099:
  for (int i = 0; i < MAX_PROCS; ++i)

2495-2498:
  ProcBonus += static_cast<float>(itembonuses.ProcChance + spellbonuses.ProcChance) / 1000.0f;
  ProcChance = 0.05f + static_cast<float>(mydex) / 9000.0f;
  ProcBonus += (ProcChance * static_cast<float>(AABonus)) / 100.0f;

2532:
  for(r = 0; r < MAX_AUGMENT_SLOTS; ++r) {

2542:
  ProcChance *= (100.0f+static_cast<float>(aug->ProcRate))/100.0f;

2568:
  float WPC = ProcChance*(100.0f+static_cast<float>(weapon->ProcRate))/100.0f;

2594:
  //float procmod =  static_cast<float>(GetDEX()) / 100.0f + ProcBonus*100.0f;  //did somebody think about this??? //unused

2607:
  int chance = static_cast<int>(ProcChance + static_cast<float>(SpellProcs[i].chance));

2831:
  for(int bs = 0; bs < BUFF_COUNT; ++bs){

2838:
  --buffs[bs].numhits;
Please don't read into any of my statements as though I'm being snide or crass, I'm not using any emotion, and I did not have any hurt feelings by your remarks. I understand making change can be difficult without proper source control in a fully trusted environment. A project such as this would not exist if it were up to one person alone, so this is expected. But please accept all of my changes, I've given every line in the original attack.cpp great thought.
__________________
Expert developer, I do it for a living.
Don't let the "Junior" tag fool you.

Last edited by trevius; 10-10-2008 at 02:12 PM..
Reply With Quote