unsigned long loopexit=0;
void checkauto() // Check automatic/timer controlled stuff (Like fighting and regeneration){	//int k;	unsigned int i,currenttime=uiCurrentTime; //\/ getclock only once	static unsigned int checkspawnregions=0;	static unsigned int checknpcs=0;	static unsigned int checktamednpcs=0;	static unsigned int checknpcfollow=0;	static unsigned int checkitemstime=0;	static unsigned int lighttime=0;	static unsigned int htmltime=0;	static unsigned int housedecaytimer=0;	//static unsigned int repairworldtimer=0;	if (housedecaytimer<=currenttime)	{		//////////////////////		///// check_houses		/////////////////////		if(SrvParms->housedecay_secs!=-1)			HouseManager->CheckDecayStatus();		////////////////////		// check stabling		///////////////////		int ci,serial; //,serhash;		unsigned long int diff;		//char * t;		//t[-1000000]=0;		//strcpy(0, "lala"); // x-wolf test :)		AllCharsIterator iter_char;		   		for (iter_char.Begin(); iter_char.GetData() != NULL; iter_char++)		{			P_CHAR pc = iter_char.GetData();			if (pc->npc_type == 1)			{				serial = pc->serial;				vector<SERIAL> pets = stablesp.getData(serial);				for (ci = 0; ci < pets.size();ci++)				{					P_CHAR pc_pet = FindCharBySerial(pets[ci]);					if (pc_pet != NULL)					{						diff = (getNormalizedTime() - pc_pet->timeused_last) / MY_CLOCKS_PER_SEC;						pc_pet->time_unused+=diff;						//clConsole.send("stabling-check debug-name: %s\n",chars[i].name);					}				}			}		}		housedecaytimer=uiCurrentTime+MY_CLOCKS_PER_SEC*60*11; // check only each 11 minutes	}	if(checkspawnregions<=currenttime && speed.srtime != -1)//Regionspawns	{		for(i=1;i<spawnregion.size();i++)		{			if(spawnregion[i].nexttime<=currenttime)			{				spawnregion[i].nexttime=currenttime+(MY_CLOCKS_PER_SEC*60*RandomNum(spawnregion[i].mintime,spawnregion[i].maxtime));				if (doregionspawn(i)) break;			}		}		checkspawnregions=uiCurrentTime+speed.srtime*MY_CLOCKS_PER_SEC;//Don't check them TOO often (Keep down the lag)	}	if(SrvParms->html>0 && (htmltime<=currenttime || overflow))	{			updatehtml();			htmltime=currenttime+(SrvParms->html*MY_CLOCKS_PER_SEC);	}	if (saveinterval != 0)	{		if (autosaved == 0)		{			autosaved = 1;			time( (time_t*) (&oldtime)) ;		}		time( (time_t*) ( &newtime)) ;		if (dosavewarning==1)		if (difftime(newtime,oldtime)==saveinterval-10) 		{		   sysbroadcast("World will be saved in 10 seconds..");		   dosavewarning = 0;		}		if (difftime(newtime, oldtime)>=saveinterval || cwmWorldState->Saving() )		{			autosaved = 0;			cwmWorldState->savenewworld(0);			dosavewarning = 1;		}		// Dupois - Added Dec 20, 1999		//			After an automatic world save occurs, lets check to see if		//			anyone is online (clients connected). If nobody is connected		//			Lets do some maintenance on the bulletin boards.	/*		if( !now )		{				clConsole.send("WOLFPACK: No players currently online. Starting bulletin board maintenance.\n" );				savelog( "Bulletin Board Maintenance routine running (AUTO)\n", "server.log" );			MsgBoardMaintenance();		}		*/	}	//Time functions	if (uotickcount<=currenttime||(overflow))	{		if (minute < 59) {minute++;hbu++;}		else		{			minute=0;			if (hour < 12) hour++;			else			{				hour = 1;				ampm = !ampm;				if (!ampm) day++;			}		}		uotickcount=currenttime+secondsperuominute*MY_CLOCKS_PER_SEC;		if (minute%8==0)			moon1=(moon1+1)%8;		if (minute%3==0)			moon2=(moon2+1)%8;	}	if(lighttime<=currenttime || (overflow))	{		doworldlight(); //Changes lighting, if it is currently time to.		for (i=0;i<now;i++) if (online(currchar[i])) dolight(i,worldcurlevel); // bandwidth fix, LB		lighttime=currenttime+30*MY_CLOCKS_PER_SEC;	}	static unsigned int itemlooptime = 0;    if(itemlooptime <=currenttime || (overflow))	{       itemlooptime = currenttime+5*MY_CLOCKS_PER_SEC;	   AllItemsIterator iterItems;       for( iterItems.Begin(); iterItems.GetData() != iterItems.End(); iterItems++ ) // Ripper...so spawners get set to nodecay.	   {			P_ITEM pi = iterItems.GetData();			if(pi != NULL)			{				// lets make sure they are spawners.				if ((pi->type>=61 && pi->type<=65) || (pi->type==69) || (pi->type==125))				{					// set to nodecay and refresh.	                pi->priv=0;		            RefreshItem(pi);				 }			}		}	}	for(i=0;i<now;i++)	{		if (online(currchar[i]) && chars[currchar[i]].account==acctno[i])		{			genericCheck(currchar[i],currenttime);			checkPC(currchar[i],currenttime);			int	StartGrid=mapRegions->StartGrid(chars[currchar[i]].pos.x,chars[currchar[i]].pos.y);			unsigned int increment=0;			unsigned long loopexit=0;			for (unsigned int checkgrid=StartGrid+(increment*mapRegions->GetColSize());increment<3;increment++, checkgrid=StartGrid+(increment*mapRegions->GetColSize()))			{				for (int a=0;a<3;a++)				{					vector<SERIAL> vecEntries = mapRegions->GetCellEntries(checkgrid + a);					for ( unsigned int k = 0; k < vecEntries.size(); k++)					{						P_CHAR mapchar = FindCharBySerial(vecEntries[k]);						P_ITEM mapitem = FindItemBySerial(vecEntries[k]);						if (mapchar != NULL)						{//Instalog //AntiChrist								//AntiChrist								//so we can use two different speeds								//for checking tamed and non-tamed npcs!								//players WANT to have faster tamed npcs....							if( (!mapchar->tamed && checknpcs<=currenttime) || (mapchar->tamed && checktamednpcs<=currenttime) || (mapchar->npcWander==1 && checknpcfollow<=currenttime) || overflow)							{								if (mapchar->isNpc()) 									genericCheck(DEREF_P_CHAR(mapchar),currenttime); // lb, lagfix								if (chardist(currchar[i], DEREF_P_CHAR(mapchar))<=24 && mapchar->isNpc()) //Morrolan tweak from 30 to 24 tiles									checkNPC(mapchar, currenttime);								else if (mapchar->isPlayer() &&									Accounts->GetInWorld(mapchar->account) == DEREF_P_CHAR(mapchar) && mapchar->logout>0 &&									(mapchar->logout<=currenttime || (overflow)))								{																			Accounts->SetOffline(mapchar->account);									mapchar->logout=-1;									updatechar(DEREF_P_CHAR(mapchar));								}							}						}						else if (mapitem != NULL && (checkitemstime<=currenttime||(overflow))) // moroallan !!! -1 is important !!!						{//BugFix							Items->RespawnItem(currenttime, mapitem);							if(mapitem->type == 51 || mapitem->type == 52) // LB !!!!							{								if(mapitem->gatetime<=currenttime) // LB !!!								{									for (k=0;k<2;k++) 										Items->DeleItem(mapitem); // bugfix for items disappearing								}							}							Items->DecayItem(currenttime, mapitem);							if (mapitem->type==88 && mapitem->morey<25 )							{								if (itemdist(currchar[i], mapitem)<=mapitem->morey)								{									if (RandomNum(1,100)<=mapitem->morez)										soundeffect4(mapitem,i, mapitem->morex>>8, mapitem->morex%256);								}							}						} else if (mapitem != NULL) {//Boats							if(mapitem->type==117 &&								(mapitem->type2==1 || mapitem->type2==2)&&								(mapitem->gatetime<=currenttime||overflow))							{								if (mapitem->type2==1) 									Boats->Move(i, mapitem->dir, mapitem);								else 								{									int dir = mapitem->dir+4;									if (dir>7) dir-=8; // LB, BUGKILLING !!!									Boats->Move(i, dir, mapitem);								}								mapitem->gatetime=(unsigned int)(currenttime + (double)(SrvParms->boatspeed*MY_CLOCKS_PER_SEC));							}							}					}				}			}		}	}//for i<now	AllTmpEff->Check();	if(checknpcs<=currenttime) checknpcs=(unsigned int)((double)(speed.npctime*MY_CLOCKS_PER_SEC+currenttime)); //lb	if(checktamednpcs<=currenttime) checktamednpcs=(unsigned int)((double) currenttime+(speed.tamednpctime*MY_CLOCKS_PER_SEC)); //AntiChrist	if(checknpcfollow<=currenttime) checknpcfollow=(unsigned int)((double) currenttime+(speed.npcfollowtime*MY_CLOCKS_PER_SEC)); //Ripper	if(checkitemstime<=currenttime) checkitemstime=(unsigned int)((double)(speed.itemtime*MY_CLOCKS_PER_SEC+currenttime)); //lb	//if(shoprestocktime<=currenttime) shoprestocktime=currenttime+(shoprestockrate*60*MY_CLOCKS_PER_SEC);	if(SrvParms->shoprestock==1 && shoprestocktime<=currenttime)	{		shoprestocktime=currenttime+(shoprestockrate*60*MY_CLOCKS_PER_SEC);		restock(0);	}	if (nextnpcaitime <= currenttime)		nextnpcaitime = (unsigned int)((double) currenttime + (speed.npcaitime*MY_CLOCKS_PER_SEC)); // lb	if (nextfieldeffecttime <= currenttime)		nextfieldeffecttime = (unsigned int)((double) currenttime + (0.5*MY_CLOCKS_PER_SEC));	if (nextdecaytime <= currenttime)		nextdecaytime = currenttime + (15*MY_CLOCKS_PER_SEC); // lb ...	if (SrvParms->auto_a_reload > 0 && Accounts->lasttimecheck + (SrvParms->auto_a_reload*60*MY_CLOCKS_PER_SEC) <= currenttime)		Accounts->CheckAccountFile();	// Do Eclipse stuff.. /blackwind 	if (SrvParms->eclipsetimer>0) 	{ 		if (SrvParms->eclipsetimer <= uiCurrentTime) 		{ 			SrvParms->eclipsetimer = (unsigned int)((double) uiCurrentTime +(ECLIPSETIMER*MY_CLOCKS_PER_SEC)); 			if (SrvParms->eclipsemode)				worldfixedlevel--;			else 				worldfixedlevel++; 			setabovelight(worldfixedlevel); 			if ((worldfixedlevel>20) ||(worldfixedlevel < 1)) 			{ 				SrvParms->eclipsetimer = 0; 				server_data.eclipsemode=!server_data.eclipsemode; 			} 		} 	} // end eclipse / blackwind..}