rem: console.write( "Starting convert timer" ); 
context: function InfidelityAura( source, time ){	// Defines the effects of the Infidelity Aura. Changes ownership of entity when only one player's units surrounds them.	this.source = source;		this.time = time;		this.count = new Array( 9 );	for( i = 0; i <= 8; i++ )	{		this.count[i] = 0;	}		this.convertTimer = 0;			this.affects = function( e ) 	{		return ( e.player.id != 0 && ( !e.traits.auras || !e.traits.auras.infidelity ) );	}		this.onEnter = function( e ) 	{		if( this.affects( e ) ) 		{			//console.write( "Infidelity aura: adding +1 count to " + e.player.id );			this.count[e.player.id]++;			this.changePlayerIfNeeded();		}	};		this.onExit = function( e ) 	{		if( this.affects( e ) ) 		{			//console.write( "Infidelity aura: adding -1 count to " + e.player.id );			this.count[e.player.id]--;			this.changePlayerIfNeeded();		}	};		this.changePlayerIfNeeded = function()	{		if( this.count[this.source.player.id] == 0 )		{			// If our owner has nothing near us but someone else does, start a time to convert over if we haven't done so already			if( !this.convertTimer )			{				for( i = 1; i <= 8; i++ )				{					if( this.count[i] > 0 )					{						console.write( "Starting convert timer" );						this.convertTimer = setTimeout( this.convert, parseInt( this.time * 1000 ), this );						return;					}				}			}		}				// If we had started a convert timer before, cancel it (either we have units from our owner in range, or there are no units from anyone in range)		if( this.convertTimer )		{			console.write( "Cancelling convert timer" );			cancelTimer( this.convertTimer );			this.convertTimer = 0;		}	}		this.convert = function()	{		console.write( "Conversion time!" );				// Switch ownership to whichever non-gaia player has the most units near us		bestPlayer = 0;		bestCount = 0;		for( i = 1; i <= 8; i++ )		{			if( this.count[i] > bestCount )			{				bestCount = this.count[i];				bestPlayer = i;			}		}		if( bestCount > 0 )		{			//console.write( "Infidelity aura: changing ownership to " + bestPlayer );			this.source.player = players[bestPlayer];		}				this.convertTimer = 0;	}}
meta: 1070	/local1/tlutelli/issta_data/temp/all_js/javascript/2007_temp/2007/1070/f38149942b7906b6181f42a456b6571b8745714c/entity_functions.js/buggy/binaries/data/mods/official/scripts/entity_functions.js