var Constructor = function()
{
    this.getWeatherName = function()
    {
        return qsTr("Thunderstorm");
    };

    this.getDescription = function()
    {
        return qsTr("A severe storm with lightning. Reduces the effectiveness of high-tech units, disables GPS/guided weapons, and limits vision.");
    };

    this.getWeatherSymbol = function()
    {
        return "weather_symbol_thunderstorm";
    };
	
	this.getWeatherTerrainSprite = function()
	{
	    return "thunderstorm";
	};

    this.getVisionrangeModifier = function(weather, map, unit, terrain)
    {
        var affectedUnits = ["RADAR", "ICBM", "ASHM", "BMDS", "AWACS", "SPAAGM", "SEAD", "COMMANDVEHICLE", "DRONE", "SUICIDE_DRONE", "FPV_DRONE", "GCS", "MISSILE_TRAIN", "MISSILE_DEF"];

        if (unit !== null)
        {
            var unitID = unit.getUnitID();
            if (affectedUnits.indexOf(unitID) !== -1)
            {
                return -99;
            }
        }
        return -1;
    };

    this.getOffensiveModifier = function(weather, attacker, defender, map)
    {
        return -5;
    };

    this.getFirerangeModifier = function(weather, map, unit)
    {
        var affectedUnits = ["RADAR", "ICBM", "VANGUARD", "ASHM", "BMDS", "AWACS", "SPAAGM", "SEAD", "COMMANDVEHICLE", "DRONE", "SUICIDE_DRONE", "FPV_DRONE", "GCS", "MISSILE_TRAIN", "MISSILE_DEF"];

        if (unit !== null)
        {
            var unitID = unit.getUnitID();
            if (affectedUnits.indexOf(unitID) !== -1)
            {
                return -99;
            }
        }
        return 0;
    };

    this.activate = function(weather, map)
    {
        var animationCount = GameAnimationFactory.getAnimationCount();
        var queueAnimation = null;
        if (animationCount > 0)
        {
            queueAnimation = GameAnimationFactory.getAnimation(animationCount - 1);
        }
        var animation = GameAnimationFactory.createAnimation(map, 0, 0);
        
        animation.addSprite2("white_pixel", 0, 0, 3200, map.getMapWidth(), map.getMapHeight());
        animation.addTweenColor(0, "#60000000", "#60000000", 3000, true);
        
        animation.setSound("thunder.wav"); 
        animation.setStartOfAnimationCall("ANIMATION", "preOnAnimationChangedAnimation");

        var variable = weather.getVariables().createVariable("FOGMODE");
        var fogMode = map.getGameRules().getFogMode();
        variable.writeDataInt32(fogMode);
        
        if (fogMode < GameEnums.Fog_OfWar)
        {
            map.getGameRules().setFogMode(GameEnums.Fog_OfWar);
        }
        
        if (queueAnimation !== null)
        {
            queueAnimation.queueAnimation(animation);
        }
    };
	
	this.deactivate = function(weather, map)
	{
	    var variable = weather.getVariables().getVariable("FOGMODE");
	    if (variable !== null)
	    {
	        var mode = variable.readDataInt32();
	        map.getGameRules().setFogMode(mode);
	    }
	};

    this.getDefaultWeatherChance = function()
    {
        return 0;
    };
}

Constructor.prototype = WEATHER;
var WEATHER_THUNDERSTORM = new Constructor();