From e4cf72e94981c015e9916dadce6fa99fe7aa12d2 Mon Sep 17 00:00:00 2001 From: Matei Date: Tue, 13 Dec 2005 21:43:08 +0000 Subject: [PATCH] Rewrote InfidelityAura in a more correct way (if there are units from several players but none from your owner near you, you should switch to the player with the most units, not remain with your current owner; also, don't count other infidel things as units of your own player near you, so groups can be converted together). This was SVN commit r3240. --- .../entities/template_entity_script.js | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/binaries/data/mods/official/entities/template_entity_script.js b/binaries/data/mods/official/entities/template_entity_script.js index e192be5f3a..39fc28675a 100644 --- a/binaries/data/mods/official/entities/template_entity_script.js +++ b/binaries/data/mods/official/entities/template_entity_script.js @@ -10,11 +10,11 @@ function entity_event_initialize( evt ) { case "courage": a = this.traits.auras.courage; - this.addAura( name, a.radius, new CourageAura( this, true, a.bonus ) ); + this.addAura( name, a.radius, new DamageModifyAura( this, true, a.bonus ) ); break; case "fear": a = this.traits.auras.fear; - this.addAura( name, a.radius, new CourageAura( this, false, -a.bonus ) ); + this.addAura( name, a.radius, new DamageModifyAura( this, false, -a.bonus ) ); break; case "infidelity": a = this.traits.auras.infidelity; @@ -539,7 +539,7 @@ function entity_CheckQueueReq (entry) // ==================================================================== -function CourageAura( source, ally, bonus ) +function DamageModifyAura( source, ally, bonus ) { this.source = source; this.bonus = bonus; @@ -590,7 +590,7 @@ function InfidelityAura( source ) this.affects = function( e ) { - return ( e.player.id != 0 ); + return ( e.player.id != 0 && ( !e.traits.auras || !e.traits.auras.infidelity ) ); } this.onEnter = function( e ) @@ -615,20 +615,24 @@ function InfidelityAura( source ) this.changePlayerIfNeeded = function() { - numNearby = 0; - someoneNearby = 0; - for( i = 1; i <= 8; i++ ) + if( this.count[this.source.player.id] == 0 ) { - if( this.count[i] > 0 ) + // switch ownership to whoever has the most units near us, if any + bestPlayer = 0; + bestCount = 0; + for( i = 1; i <= 8; i++ ) { - numNearby++; - someoneNearby = 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]; } - } - if( numNearby == 1 ) - { - console.write( "Infidelity aura: changing ownership to " + someoneNearby ); - this.source.player = players[someoneNearby]; } } } \ No newline at end of file