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

    this.getDescription = function()
    {
        return qsTr("Corrosive rain that reduces unit vision and weakens armor. Damages -1 hp to infantry each day and increases the fuel consumption of flying and remote units. Enforces Fog of War.");
    };

    this.getWeatherTerrainSprite = function()
    {
        return "acid_rain";
    };

    this.getWeatherSymbol = function()
    {
        return "weather_symbol_acid_rain";
    };

    this.getVisionrangeModifier = function()
    {
        return -1;
    };

    this.getDefensiveModifier = function()
    {
        return -10;
    };

    this.getMovementFuelCostModifier = function(weather, unit, fuelCost)
    {
        var uType = unit.getUnitType();
        if (uType === GameEnums.UnitType_Air || 
            uType === GameEnums.REMOTE_WEAPON || 
            uType === GameEnums.HELICOPTER || 
            uType === GameEnums.DRONE)
        {
            return 1;
        }
        return 0;
    };

    this.onStartOfTurn = function(weather, unit, map)
    {
        if (unit.getTerrain() !== null)
        {
            if (unit.getUnitType() === GameEnums.UnitType_Infantry)
            {
                if (!unit.getWeatherImmune())
                {
                    if (unit.getOwner() === map.getCurrentPlayer())
                    {
                        unit.setHp(unit.getHp() - 1);
                        
                        var viewPlayer = map.getCurrentViewPlayer();
                        var isVisible = false;
                        if (viewPlayer !== null)
                        {
                            var vision = viewPlayer.getFieldVisibleType(unit.getX(), unit.getY());
                            if (vision === GameEnums.VisionType_Clear || vision === GameEnums.VisionType_Mist)
                            {
                                isVisible = true;
                            }
                        }
                        
                        if (isVisible)
                        {
                            var damageAnimation = GameAnimationFactory.createAnimation(map, unit.getX(), unit.getY());
                            damageAnimation.addSprite("poison", 0, 0, 300, 2);
                        }
                        
                        if (unit.getHp() <= 0)
                        {
                            unit.killUnit();
                        }
                    }
                }
            }
        }
    };

    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, "#00FFFFFF", "#FFFFFFFF", 3000, true);
        animation.setSound("radiation.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_ACID_RAIN = new Constructor();