rem: pool = this.traits.loot; for( loot in pool ) 
add: for( loot in this.traits.loot ) 
context: function damage( dmg, inflictor ){		if(!this.traits.armour) return;		// corpses have no armour, everything else should		this.last_combat_time = getGameTime();	// Apply armour and work out how much damage we actually take	crushDamage = parseInt(dmg.crush - this.traits.armour.value * this.traits.armour.crush);	if ( crushDamage < 0 ) crushDamage = 0;	pierceDamage = parseInt(dmg.pierce - this.traits.armour.value * this.traits.armour.pierce);	if ( pierceDamage < 0 ) pierceDamage = 0;	hackDamage = parseInt(dmg.hack - this.traits.armour.value * this.traits.armour.hack);	if ( hackDamage < 0 ) hackDamage = 0;	totalDamage = parseInt(dmg.typeless + crushDamage + pierceDamage + hackDamage);	// Minimum of 1 damage	if( totalDamage < 1 ) totalDamage = 1;	this.traits.health.curr -= totalDamage;	if( this.traits.health.curr <= 0 )	{		// If the fallen is worth any loot and the inflictor is capable of looting		if (this.traits.loot && inflictor.actions.loot)		{			// Cycle through all loot on this entry.			pool = this.traits.loot;			for( loot in pool )			{				switch( loot.toString().toUpperCase() )				{					case "XP":						// If the inflictor gains promotions, and he's capable of earning more ranks,						if (inflictor.traits.promotion && inflictor.traits.promotion.curr && inflictor.traits.promotion.req								&& inflictor.traits.promotion.newentity && inflictor.traits.promotion.newentity != ""								&& this.traits.loot && this.traits.loot.xp && inflictor.actions.loot.xp)						{							// Give him the fallen's upgrade points (if he has any).							if (this.traits.loot.xp)								inflictor.traits.promotion.curr = parseInt(inflictor.traits.promotion.curr) + parseInt(this.traits.loot.XP);							// Notify player.							if (inflictor.traits.id.specific)								console.write(inflictor.traits.id.specific + " has earned " + this.traits.loot.xp + " upgrade points!");							else								console.write("One of your units has earned " + this.traits.loot.xp + " upgrade points!");							// If he now has maximum upgrade points for his rank,							if (inflictor.traits.promotion.curr >= inflictor.traits.promotion.req)							{								// Notify the player.								if (inflictor.traits.id.specific)									console.write(inflictor.traits.id.specific + " has gained a promotion!");								else									console.write("One of your units has gained a promotion!");																// Reset his upgrade points.								inflictor.traits.promotion.curr = 0; 								// Upgrade his portrait to the next level.								inflictor.traits.id.icon_cell++; 								// Transmogrify him into his next rank.								inflictor.template = getEntityTemplate(inflictor.traits.promotion.newentity);							}						}					break;					default:						if ( inflictor.actions.loot.resources ) 						{							// Give the inflictor his resources.							getGUIGlobal().giveResources( loot.toString(), parseInt(pool[loot]) );							// Notify player.							console.write ("Spoils of war! " + pool[loot] + " " + loot.toString() + "!");						}					break;				}			}		}		// Notify player.		if ( inflictor )			console.write( this.traits.id.generic + " got the point of " + inflictor.traits.id.generic + "'s weapon." );		else			console.write( this.traits.id.generic + " died in mysterious circumstances." );		// Make him cry out in pain.		if (this.traits.audio && this.traits.audio.path)		{			curr_pain = getGUIGlobal().newRandomSound("voice", "pain", this.traits.audio.path);			if (curr_pain) curr_pain.play();		}		else		{			console.write ("Sorry, no death sound for this unit; you'll just have to imagine it ...");		}		// We've taken what we need. Kill the swine.		console.write("Kill!!");		this.kill();	}	else if( inflictor && this.actions.attack )	{		// If we're not already doing something else, take a measured response - hit 'em back.		// You know, I think this is quite possibly the first AI code the AI divlead has written		// for 0 A.D....		if( this.isIdle() )			this.order( ORDER_GENERIC, inflictor, getAttackAction( this, inflictor ) );	}}
meta: 1070	/local1/tlutelli/issta_data/temp/all_js/javascript/2006_temp/2006/1070/5b10fce4a73858267f89281e17c8ea59d4f7e106/template_entity_script.js/buggy/binaries/data/mods/official/entities/template_entity_script.js