P_CHAR pc = ri.GetData(); if (pc != NULL)
P_PLAYER pc = dynamic_cast<P_PLAYER>(ri.GetData()); if( pc )
void bgsound(P_CHAR pc){	int sound;	int distance=(VISRANGE+5);	vector<P_CHAR> inrange;	int basesound=0;	int bigf,xx;	char sf,bfs;	if (pc == NULL) return;	int y=0;	RegionIterator4Chars ri(pc->pos());	for (ri.Begin(); !ri.atEnd(); ri++)	{		P_CHAR pc = ri.GetData();		if (pc != NULL)		{			if((pc->isPlayer())&&(!(pc->dead()))&&(!(pc->war()))&&(y<=10))			{				if (!pc->free) // lb, bugfix !				{					if (inRange(pc->pos().x, pc->pos().y, pc->pos().x, pc->pos().y, distance))					{						inrange.push_back(pc);					}				}			}		}	}	if (inrange.size() > 0)	{		sound=RandomNum(0, inrange.size()-1);		xx = inrange[sound]->id();		if (xx>-1 && xx<2048)		{			basesound=creatures[xx].basesound;			sf=creatures[xx].soundflag;		}		else return;		if (basesound!=0)		{			switch(sf) // play only idle sounds, if there arnt any, dont play them !			{			case 0: basesound++; break;	// normal case -> play idle sound			case 1: basesound++; break;	// birds sounds will be implmented later			case 2:	basesound=0; break;	// no idle sound, so dont play it !			case 3: basesound=0; break;	// no idle sound, so dont play it !			case 4:	break; // only a single sound, play it !			}			if (bgsound!=0) // bugfix lb			{				/*sfx[2]=basesound>>8;				sfx[3]=basesound%256;				sfx[6]=inrange[sound]->pos().x>>8;				sfx[7]=inrange[sound]->pos().x%256;				sfx[8]=inrange[sound]->pos().y>>8;				sfx[9]=inrange[sound]->pos().y%256;				Xsend(calcSocketFromChar(pc), sfx, 12); //bugfix, LB*/			}		}	}	// play random mystic-sounds also if no creature is in range ...	bigf=rand()%3333;	basesound=0;	if (bigf==33)	{		bfs=rand()%7;		switch(bfs)		{		case 0: basesound=595;break; // gnome sound		case 1: basesound=287;break; // bigfoot 1		case 2: basesound=288;break; // bigfoot 2		case 3: basesound=639;break; // old snake sound		case 4: basesound=179;break; // lion sound		case 5: basesound=246;break; // mystic		case 6: basesound=253;break; // mystic II		}		if (basesound !=0)		{			/*sfx[2] = (unsigned char) (basesound>>8);			sfx[3] = (unsigned char) (basesound%256);			sfx[6] = (unsigned char) (pc->pos().x>>8);			sfx[7] = (unsigned char) (pc->pos().x%256);			sfx[8] = (unsigned char) (pc->pos().y>>8);			sfx[9] = (unsigned char) (pc->pos().y%256);			Xsend(calcSocketFromChar(pc), sfx, 12); //bugfix LB*/		}	}}