rem: if( this.building != "" ) 
add: if( this.building && this.building != "" ) 
context: function entityInit(){	// Initialise an entity when it is first spawned (generate starting hitpoints, etc).	this.addCreateQueue = entityAddCreateQueue;		// If this is a foundation, initialize traits from the building we're converting into	if( this.building != "" )	{		var building = getEntityTemplate( this.building );		this.traits.id.generic = building.traits.id.generic;		this.traits.id.specific = building.traits.id.specific;		this.traits.id.civ = building.traits.id.civ;		this.traits.id.icon_cell = building.traits.id.icon_cell;		this.traits.health.max = building.traits.health.max;		this.build_points = new Object();		this.build_points.curr = 0.0;		this.build_points.max = parseFloat( building.traits.creation.time );	}		// Generate civ code (1st four characters of civ name, in lower case eg "Carthaginians" => "cart").	if (this.traits.id && this.traits.id.civ)	{		this.traits.id.civ_code = this.traits.id.civ.toString().substring (0, 4)		this.traits.id.civ_code = this.traits.id.civ_code.toString().toLowerCase()		// Exception to make the Romans into rome.		if (this.traits.id.civ_code == "roma") this.traits.id.civ_code = "rome"		// Exception to make the Hellenes into hele.		if (this.traits.id.civ_code == "hell") this.traits.id.civ_code = "hele"	}	// 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 ( this.traits.health && this.traits.health.max  )		this.traits.health.curr = ( this.building!="" ? 0.0 : this.traits.health.max );	// If entity has stamina, set current to same.	if ( this.traits.stamina && this.traits.stamina.max )		this.traits.stamina.curr = this.traits.stamina.max;	if (this.traits.supply)	{		// If entity has supply, set current to same.		if (this.traits.supply.max)			this.traits.supply.curr = this.traits.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 (this.traits.supply.type && !this.traits.supply.subtype)			this.traits.supply.subtype = this.traits.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).		this.traits.supply.dropsitecount = new Array();		initialCount = this.traits.supply.subtype.meat ? 1 : 0;		for( i=0; i<=8; i++ )		{			this.traits.supply.dropsitecount[i] = initialCount;		}	}	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)	{		// Get the name of the entity. 		entityName = this.tag.toString();			// Determine whether current is basic, advanced or elite, and set rank to suit.		switch (entityName.substring (entityName.length-2, entityName.length))		{			case "_b":				// Basic. Upgrades to Advanced.				this.traits.promotion.rank = "1"				nextSuffix = "_a"			break;			case "_a":				// Advanced. Upgrades to Elite.				this.traits.promotion.rank = "2"				nextSuffix = "_e"			break;			case "_e":				// Elite. Maximum rank.				this.traits.promotion.rank = "3"				nextSuffix = ""			break;			default:				// Does not gain promotions.				this.traits.promotion.rank = "0"				nextSuffix = ""			break;		}				// 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			// The entity it should become (unless specified otherwise) is the base entity plus promotion suffix.		if (!this.traits.promotion.newentity && nextSuffix != "" && this.traits.promotion.rank != "0")			this.traits.promotion.newentity = entityName.substring (0, entityName.length-2) + nextSuffix		// If entity is an additional rank and the correct actor has not been specified		// (it's just inherited the Basic), point it to the correct suffix. (Saves us specifying it each time.)		actorStr = this.actor.toString();		if (this.traits.promotion.rank > "1"			&& actorStr.substring (actorStr.length-5, actorStr.length) != nextSuffix + ".xml")			this.actor = actorStr.substring (1,actorStr.length-5) + nextSuffix + ".xml";	}	else	{		this.traits.promotion.rank = "0";	}		// Register our actions with the generic order system	if( this.actions )	{		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" );		}	}		// Attach functions to ourselves		this.performAttack = performAttack;	this.performAttackRanged = performAttackRanged;	this.performGather = performGather;	this.performHeal = performHeal;	this.performBuild = performBuild;	this.damage = damage;	this.entityComplete = entityComplete;	this.GotoInRange = GotoInRange;	this.attachAuras = attachAuras;	this.attachAuras();		if ( !this.traits.id )	{		this.traits.id = new Object();	}		// 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)			getGUIGlobal().giveResources ("Housing", this.traits.population.add);		// If the entity occupies population slots (occupies Housing),		if (this.traits.population.rem)			getGUIGlobal().giveResources ("Population", this.traits.population.rem);	}		// Build Unit AI Stance list, and set default stance.	if ( !this.traits.ai )		this.traits.ai = new Object();	if ( !this.traits.ai.stance )		this.traits.ai.stance = new Object();	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 = "Defend";	}	else	{		// Set default stance for non-combat units.		this.traits.ai.stance.curr = "Avoid";	}	/*		// 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/25207198e4ef701d44390d410fa0013138182579/template_entity_script.js/buggy/binaries/data/mods/official/entities/template_entity_script.js