package com.srbenoit.modeling.cell;

import com.srbenoit.modeling.grid.PointGridMember2;

/**
 * A signal emitted by an emitter;
 */
public class Signal extends PointGridMember2 {

    /** the remaining life of this signal */
    private int life;

    /** the activation level this signal carries */
    private final double activation;

    /**
     * Constructs a new <code>Signal</code>.
     *
     * @param  xCoord    the X coordinate of the signal location
     * @param  yCoord    the Y coordinate of the signal location
     * @param  lifetime  the lifetime of the signal
     * @param  actLevel  the activation level this signal carries
     */
    public Signal(final double xCoord, final double yCoord, final int lifetime,
        final double actLevel) {

        super(xCoord, yCoord);

        this.life = lifetime;
        this.activation = actLevel;
    }

    /**
     * Ages the signal, decrementing its remaining life.
     *
     * @return  the remaining life after aging
     */
    public int age() {

        this.life--;

        return this.life;
    }

    /**
     * Kills the signal (sets its life to zero). Called when a signal is absorbed. The signal is
     * not removed from the grid.
     */
    public void die() {

        this.life = 0;
    }

    /**
     * Test whether a signal is still alive.
     *
     * @return  <code>true</code> if the signal is still alive
     */
    public boolean isLiving() {

        return this.life > 0;
    }

    /**
     * Gets the activation level this signal carries.
     *
     * @return  the activation level
     */
    public double getActivation() {

        return this.activation;
    }
}
