View Single Post
  #1  
Old 06-10-2002, 01:22 AM
Wiz
Dragon
 
Join Date: Feb 2002
Posts: 583
Default 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;
}
Reply With Quote