pItem->tags().set("gatetime", (int)( currenttime + (double)( SrvParams->boatSpeed() * MY_CLOCKS_PER_SEC ) ) );
pItem->setTag("gatetime", (int)( currenttime + (double)( SrvParams->boatSpeed() * MY_CLOCKS_PER_SEC ) ) );
void checkauto() // Check automatic/timer controlled stuff (Like fighting and regeneration){	//int k;	unsigned int currenttime = uiCurrentTime;	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 housedecaytimer = 0;	if( shoprestocktime == 0 )		shoprestocktime = currenttime + MY_CLOCKS_PER_SEC * 60 * 20;	//static unsigned int repairworldtimer=0;	if (housedecaytimer<=currenttime)	{		//////////////////////		///// check_houses		/////////////////////		if(SrvParams->housedecay_secs() != -1)			check_house_decay();/*	TODO: rewrite STABLEMASTER with python		////////////////////		// check stabling		///////////////////		unsigned long int diff;		cCharIterator iter_char;		for( P_CHAR pc = iter_char.first(); pc; pc = iter_char.next() )		{			if( pc->npc_type() == 1 )			{				vector<SERIAL> pets( stablesp.getData(pc->serial()) );				unsigned int ci;				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->setTime_unused( pc_pet->time_unused() + diff );					}				}			}		}*/		housedecaytimer=uiCurrentTime+MY_CLOCKS_PER_SEC*60*30; // check only each 30 minutes	}	if(checkspawnregions<=currenttime && SrvParams->spawnRegionCheckTime() != -1)//Regionspawns	{		SpawnRegions::instance()->check();		checkspawnregions=uiCurrentTime+SrvParams->spawnRegionCheckTime()*MY_CLOCKS_PER_SEC;//Don't check them TOO often (Keep down the lag)	}	if( SrvParams->saveInterval() != 0 )	{		if (autosaved == 0)		{			autosaved = 1;			time( (time_t*) (&oldtime)) ;		}		time( (time_t*) ( &newtime)) ;		if (dosavewarning==1)		if (difftime(newtime,oldtime)==SrvParams->saveInterval()-10) 		{			cNetwork::instance()->broadcast( tr( "World will be saved in 10 seconds.." ) );			dosavewarning = 0;		}		if (difftime(newtime, oldtime)>=SrvParams->saveInterval() )		{			autosaved = 0;			World::instance()->save();			dosavewarning = 1;		}	}	// Recalculate and Resend Lightlevel	if( lighttime <= currenttime )	{		// Resend the lightlevel to all clients		UINT16 level = 0xFF;		if( uoTime.time().hour() <= 3 && uoTime.time().hour() >= 10 )			level = SrvParams->worldDarkLevel();		else			level = SrvParams->worldBrightLevel();		if( level == 0xFFFF )		{			level = ( ( ( 60 * ( uoTime.time().hour() - 4 ) ) + uoTime.time().minute()) * (SrvParams->worldDarkLevel()-SrvParams->worldBrightLevel())) / 360;			if(uoTime.time().hour() < 12)				level += SrvParams->worldBrightLevel();			else				level = SrvParams->worldDarkLevel() - level;		}		// Only update and resend when the lightlevel		// Really changed		if( level != SrvParams->worldCurrentLevel() )		{			SrvParams->worldCurrentLevel() = level;			cUOSocket *mSock = cNetwork::instance()->first();			while( mSock )			{				mSock->updateLightLevel( level );				mSock = cNetwork::instance()->next();			}		}		// Update lightlevel every 30 seconds		lighttime = currenttime + 30 * MY_CLOCKS_PER_SEC;	}	// Regenerate only players who are online	for( cUOSocket *socket = cNetwork::instance()->first(); socket; socket = cNetwork::instance()->next() )	{		if( !socket->player() )			continue;		checkRegeneration( socket->player(), currenttime );		checkPC( socket->player(), currenttime );		// Check all Characters first (Intersting. we seem to check characters more than once)		RegionIterator4Chars iterator( socket->player()->pos() );		for( iterator.Begin(); !iterator.atEnd(); iterator++ )		{			P_CHAR pChar = iterator.GetData();			if( !pChar )				continue;			// we check tamed npcs more often than			// untamed npcs so they can react faster			if( ( !pChar->isTamed() && checknpcs <= currenttime ) ||				( pChar->isTamed() && checktamednpcs <= currenttime ) )			{				if( pChar->objectType() == enNPC )				{					// Regenerate Mana+Stamina+Health					checkRegeneration( pChar, currenttime );					// We only process the AI for NPCs who are in a used area					if( pChar->dist( socket->player() ) <= 24 )						checkNPC( dynamic_cast<P_NPC>(pChar), currenttime );				}				// Timed for logout				else if( pChar->objectType() == enPlayer )				{					P_PLAYER pp = dynamic_cast<P_PLAYER>(pChar);					if( pp->logoutTime() && pp->logoutTime() >= currenttime )					{						pp->setLogoutTime( 0 );						pp->removeFromView( false );						pp->resend( false );					}				}			}				}		// Check the mapregions around this character. 		// This *could* be expensive when many characters are in the same		// region.		if( checkitemstime <= currenttime  )		{			RegionIterator4Items itemIter( socket->player()->pos() );			for( itemIter.Begin(); !itemIter.atEnd(); itemIter++ )			{				P_ITEM pItem = itemIter.GetData();								pItem->respawn( currenttime ); // Checks if the item is a spawner				pItem->decay( currenttime ); // Checks if the Item should decay				switch( pItem->type() )				{				// Move Boats				case 117:					{						bool ok = false;						if( pItem->tags().get( "tiller" ).isValid() && 							pItem->tags().get("gatetime").toInt(&ok) <= currenttime  && ok )						{							cBoat* pBoat = dynamic_cast< cBoat* >( FindItemBySerial( pItem->tags().get( "boatserial" ).toInt() ) );							if( pBoat )							{								pBoat->move();								pItem->tags().set("gatetime", (int)( currenttime + (double)( SrvParams->boatSpeed() * MY_CLOCKS_PER_SEC ) ) );							}						}						break;					}				};							}		}	}