EQEmulator Forums

EQEmulator Forums (https://www.eqemulator.org/forums/index.php)
-   Archive::Development (https://www.eqemulator.org/forums/forumdisplay.php?f=621)
-   -   Need some help... (https://www.eqemulator.org/forums/showthread.php?t=2298)

Wiz 06-10-2002 01:22 AM

Need some help...
 
I'm going insane about this code :/

The value I'm having problems with is the int old. It's a value set to store the critter's Y plus the critter's X. However, it's escalating to all hell, for every buff "tic" here, it raises, ending up something like 2958252291411414.

Code:

void Mob: :DoBuffTic(int16 spell_id, int32 ticsremaining, int8 caster_level, Mob* caster) {
        int tx = GetX();
        int ty = GetY();
        int old = GetOldCoords();
        if (!spells_loaded)
                return;
        if (spell_id != 0xFFFF) {
                for (int i=0; i < 12; i++) {
                        switch (spells[spell_id].effectid[i]) {
                                case SE_CurrentHP:
                                        {
                                        if (caster != 0)
                                        {
                                                adverrorinfo = 41;
                                                int val = CalcSpellValue(spells[spell_id].formula[i], spells[spell_id].base[i], spells[spell_id].max[i], caster_level);
                                                if (val < 0 && this->IsNPC())
                                                {
                                                        this->CastToNPC()->AddToHateList(caster,val*-1,val*-1);
                                                }
                                                if (old != 0 && old != tx + ty && this->IsNPC())
                                                        val = val/4;
                                                if (this->GetHP() + val < 1)
                                                        this->SetHP(1);
                                                else
                                                        this->SetHP(GetHP()+val);
                                                if (this->IsNPC())
                                                {
                                                        this->CastToNPC()->SendHPUpdate();
                                                }
                                                if (this->IsClient())
                                                        this->CastToClient()->SendHPUpdate();
                                                SetOldCoords(tx,ty);
                                                cout<<old<<endl;
                                                break;
                                        }
                                }
                                case SE_HealOverTime: {
                                        if (this->IsClient() || caster != 0){
                                                adverrorinfo = 42;
                                                this->ChangeHP(caster, CalcSpellValue(spells[spell_id].formula[i], spells[spell_id].base[i], spells[spell_id].max[i], caster_level), spell_id);
                                                adverrorinfo = 4;
                                        }
                                        break;
                                }
                                case SE_CurrentMana: {
                                        this->SetMana(GetMana() + CalcSpellValue(spells[spell_id].formula[i], spells[spell_id].base[i], spells[spell_id].max[i], caster_level));
                                        break;
                                }
                                default: {
                                        // do we need to do anyting here?
                                }
                        }
                }
        }
}

Here's the values/functions declared.

Code:

int                oldcoords;
void        SetOldCoords(int tx,int ty);
int    GetOldCoords() {return oldcoords; SetOldCoords(0,0);}
oldcoords = 0;
void Mob::SetOldCoords(int tx,int ty)
{
        oldcoords = tx+ty;
}


theCoder 06-11-2002 12:54 PM

I can't tell exactly what's going on here, but could it be that GetOldCoords has a return before the SetOldCoords call? Should it be instead:
Code:

int    GetOldCoords() { SetOldCoords(0,0); return oldcoords; }
Usually the compiler complains if you put statements after a return, though, so I'm probably missing something...


All times are GMT -4. The time now is 06:29 AM.

Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.