rem: function entityInit() 
add: function entityInit( evt ) 
context: function entityInit(){	// Initialise an entity when it is first spawned (generate starting hitpoints, etc).		// This function is called for all "full" entities - those inheriting from template_entity_full; there is a simpler version below	// called entityInitQuasi for quasi-entities (rocks, trees, etc) for which most of the things dealt with here don't apply.    startXTimer(1);	// If the entity is a foundation, we must deduct resource costs here	if( this.building )	{		var template = getEntityTemplate( this.building, this.player );		var result = checkEntityReqs( this.player, template );			if (result == true) // If the entry meets requirements to be added to the queue (eg sufficient resources) 		{			console.write("There");			// Cycle through all costs of this entry.			var pool = template.traits.creation.resource;			for ( resource in pool )			{				switch ( resource.toString() )				{					case "population":					case "housing":					break;					default:						// Deduct the given quantity of resources.						this.player.resources[resource.toString()] -= parseInt(pool[resource]);						console.write ("Spent " + pool[resource] + " " + resource + " to build " + 							template.traits.id.generic);					break;				}			}		}		else		{			// Might happen if the player clicks to place 2 buildings really fast			console.write( "Could not begin construction: " + result );			evt.preventDefault();			return;		}	}		stopXTimer(1);	startXTimer(2);		// Attach our functions to ourselves	this.getAttackAction = getAttackAction;		// Note: required by CEntity	this.performAttack = performAttack;	this.performAttackRanged = performAttackRanged;	this.performGather = performGather;	this.performHeal = performHeal;	this.performBuild = performBuild;	this.performRepair = performRepair;	this.damage = damage;	this.entityComplete = entityComplete;	this.GotoInRange = GotoInRange;	this.attachAuras = attachAuras;	this.setupRank = setupRank;		// Some temp variables to speed up property access	var id = this.traits.id;	var supply = this.traits.supply;	var health = this.traits.health;	var stamina = this.traits.stamina;		// If this is a foundation, initialize traits from the building we're converting into	if( this.building && this.building != "" )	{		var building = getEntityTemplate( this.building, this.player );		id.generic = building.traits.id.generic;		id.specific = building.traits.id.specific;		id.civ = building.traits.id.civ;		id.icon_cell = building.traits.id.icon_cell;		this.traits.health.max = building.traits.health.max;		this.buildPoints = new Object();		this.buildPoints.curr = 0.0;		this.buildPoints.max = parseFloat( building.traits.creation.time );	}		// Generate civ code (1st four characters of civ name, in lower case eg "Carthaginians" => "cart").	if( !id.civ_code && id.civ )	{		var civ_code = id.civ.toString().substring (0, 4);		civ_code = civ_code.toString().toLowerCase();		// Exception to make the Romans into rome and Hellenes into hele.		if (civ_code == "roma") civ_code = "rome";		else if (civ_code == "hell") civ_code = "hele";				id.civ_code = civ_code;	}	// If entity can contain garrisoned units, empty it.	if ( this.traits.garrison && this.traits.garrison.max )		this.traits.garrison.curr = 0;	// If entity has health, set current to same, unless it's a foundation, in which case we set it to 0.	if ( health && health.max  )		health.curr = ( this.building!="" ? 0.0 : health.max );	// If entity has stamina, set current to same.	if ( stamina && stamina.max )		stamina.curr = stamina.max    stopXTimer(2);    startXTimer(3);	if( supply )	{		// If entity has supply, set current to same.		supply.curr = supply.max;		// If entity has type of supply and no subType, set subType to same		// (so we don't have to say type="wood", subType="wood"		if (supply.type && !supply.subType)			supply.subType = supply.type;					// The "dropsiteCount" array holds the number of units with gather aura in range of the object;		// this is important so that if you have two mills near something and one of them is destroyed,		// you can still gather from the thing. Initialize it to 0 (ungatherable) for every player unless		// the entity is forageable (e.g. for huntable animals).		var dropsiteCount = new Array();		initialCount = supply.subType.meat ? 1 : 0;		for( i=0; i<=8; i++ )		{			dropsiteCount[i] = initialCount;		}		supply.dropsiteCount = dropsiteCount;	}	if (!this.traits.promotion)		this.traits.promotion = new Object();			// If entity becomes another entity after it gains enough experience points, set up secondary attributes.	if (this.traits.promotion.req)	{		this.setupRank();					// Give the entity an initial value of 0 earned XP at startup if a default value is not specified.		if (!this.traits.promotion.curr)			this.traits.promotion.curr = 0;		}	else	{		this.traits.promotion.rank = "0";	}		stopXTimer(3);	startXTimer(4);		// Register our actions with the generic order system	if( this.actions )	{		if ( this.actions.move && this.actions.move.speed )			this.actions.move.speedCurr = this.actions.move.speed;					if( this.actions.attack && this.actions.attack.melee )		{			a = this.actions.attack.melee;			minRange = ( a.minRange ? a.minRange : 0.0 );			this.setActionParams( ACTION_ATTACK, minRange, a.range, a.speed, "melee" );		}		if( this.actions.gather )		{			a = this.actions.gather;			this.setActionParams( ACTION_GATHER, 0.0, a.range, a.speed, "gather" );		}		if( this.actions.heal )		{			a = this.actions.heal;			this.setActionParams( ACTION_HEAL, 0.0, a.range, a.speed, "heal" );		}		if( this.actions.attack && this.actions.attack.ranged )		{			a = this.actions.attack.ranged;			minRange = ( a.minRange ? a.minRange : 0.0 );			// this animation should actually be "ranged" except the current actors still have it called "melee"			this.setActionParams( ACTION_ATTACK_RANGED, minRange, a.range, a.speed, "melee" );		}		if( this.actions.build )		{			this.setActionParams( ACTION_BUILD, 0.0, 2.0, this.actions.build.speed, "build" );		}		if( this.actions.repair )		{			this.setActionParams( ACTION_REPAIR, 0.0, 2.0, this.actions.repair.speed, "build" );		}	}    stopXTimer(4);    startXTimer(5);	this.attachAuras();		// If the entity either costs population or adds to it,	if (this.traits.population)	{		// If the entity increases the population limit (provides Housing),		if (this.traits.population.add)			this.player.resources.housing += parseInt(this.traits.population.add);		// If the entity takes up Housing,		if (this.traits.population.rem)			this.player.resources.population += parseInt(this.traits.population.rem);	}		// Build Unit Ai Stance list, and set default stance.  ---> Can eventually be done in C++, since stances will likely be implemented in C++.	if (this.actions && this.actions.move)	{		if ( !this.traits.ai.stance.list )			this.traits.ai.stance.list = new Object();		// Create standard stances that all units have.		this.traits.ai.stance.list.avoid = new Object();		this.traits.ai.stance.list.hold = new Object();			if ( this.actions && this.actions.attack )		{			// Create stances that units only have if they can attack.			this.traits.ai.stance.list.aggress = new Object();				this.traits.ai.stance.list.defend = new Object();			this.traits.ai.stance.list.stand = new Object();			// Set default stance for combat units.			this.traits.ai.stance.curr = "hold";		}	}			stopXTimer(5);/*		// Generate entity's personal name (if it needs one).	if (this.traits.id.personal)	{		// todo		// Look in the appropriate array for a random string.		switch (this.traits.id.classes[])		{			case "Male":				this.traits.id.personal.table1 = "Male"			break;			case "Female":				this.traits.id.personal.table1 = "Female"			break;			default:				this.traits.id.personal.table1 = "Gen"			break;			}						this.traits.id.personal.name = getRandom (this.traits.id.civ_code + this.traits.id.personal.table1 + "1")		this.traits.id.personal.name = this.traits.id.personal.name + " " + getRandom (this.traits.id.civ_code + this.traits.id.personal.table1 + "2")	}	else		this.traits.id.personal.name = "";*/	// Log creation of entity to console.	//if (this.traits.id.personal && this.traits.id.personal.name)	//	console.write ("A new " + this.traits.id.specific + " (" + this.traits.id.generic + ") called " + this.traits.id.personal.name + " has entered your dungeon.")	//else		//	console.write ("A new " + this.traits.id.specific + " (" + this.traits.id.generic + ") has entered your dungeon.")}
meta: 1070	/local1/tlutelli/issta_data/temp/all_js/javascript/2006_temp/2006/1070/3ff652eaaf33b82cfe5c2eaf707fe12a4381cee6/entity_functions.js/clean/binaries/data/mods/official/scripts/entity_functions.js