/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mobemu.node;

/**
 * Class for a device's battery.
 *
 * @author Radu
 */
public class Battery {

    private double currentLevel; // current battery level
    private long leftToRecharge; // duration until the device is fully recharged (in ticks)
    private static double maxLevel; // maximum battery level (i.e. when it is fully charged)
    private static long rechargeDuration; // duration of recharge (in ticks)
    private static double minBatteryThreshold; // threshold under which a node doesn't participate in the network any more
    private static final int NOT_CHARGING = -1;

    /**
     * Creates a {@link Battery} object.
     *
     * @param currentLevel starting level of this device's battery; if set to a
     * negative value, the level is chosen randomly between 0 and {@code maxLevel}
     * @param maxLevel the maximum allowed battery level
     * @param rechargeDuration the duration it takes for this battery to
     * recharge
     * @param minBatteryThreshold minimum battery threshold
     */
    public Battery(double currentLevel, double maxLevel, long rechargeDuration, double minBatteryThreshold) {
        this.currentLevel = currentLevel;
        this.leftToRecharge = NOT_CHARGING;

        Battery.maxLevel = maxLevel;
        Battery.rechargeDuration = rechargeDuration;
        Battery.minBatteryThreshold = minBatteryThreshold;
    }

    /**
     * Gets the current battery level.
     *
     * @return the current battery level
     */
    public double getCurrentLevel() {
        return currentLevel;
    }

    /**
     * Gets the maximum battery level.
     *
     * @return the maximum battery level
     */
    public static double getMaxLevel() {
        return maxLevel;
    }

    /**
     * Update the device's current battery level.
     */
    public void updateBatteryLevel() {
        if (leftToRecharge == NOT_CHARGING) {
            currentLevel--;

            if (currentLevel <= 0) {
                currentLevel = 0;
                leftToRecharge = 0;
            }
        } else {
            leftToRecharge++;
            if (leftToRecharge >= rechargeDuration) {
                currentLevel = maxLevel;
                leftToRecharge = NOT_CHARGING;
            }
        }
    }

    /**
     * Checks whether the current node can participate in the network (i.e. if
     * the node's battery level is higher than the minimum battery threshold).
     *
     * @return {@code true} if the node can participate, {@code false} otherwise
     */
    public boolean canParticipate() {
        return currentLevel >= minBatteryThreshold;
    }
}

@@ -642,16 +642,114 @@
 ny more%0A
+    private double decreaseRate; // the battery level decreases with this amount at every contact%0A
     priv
@@ -990,16 +990,23 @@
 en 0 and
+%0A     *
  %7B@code 
@@ -1014,16 +1014,137 @@
 axLevel%7D
+; a battery's level is the duration it takes for the%0A     * battery to completely deplete, and is measured in trace ticks
 %0A     * 
@@ -1281,16 +1281,27 @@
 recharge
+ (in ticks)
 %0A     * 
@@ -1556,16 +1556,49 @@
 HARGING;
+%0A        this.decreaseRate = 1.0;
 %0A%0A      
@@ -1952,151 +1952,755 @@
 the 
-maximum battery level.%0A     *%0A     * @return the maximum battery level%0A     */%0A    public static double getMaxLevel() %7B%0A        return maxLevel
+current battery decrease rate.%0A     *%0A     * @return the current battery decrease rate%0A     */%0A    public double getDecreaseRate() %7B%0A        return decreaseRate;%0A    %7D%0A%0A    /**%0A     * Sets the default battery decrease rate.%0A     */%0A    public void resetDecreaseRate() %7B%0A        decreaseRate = 1.0;%0A    %7D%0A%0A    /**%0A     * Gets the maximum battery level.%0A     *%0A     * @return the maximum battery level%0A     */%0A    public static double getMaxLevel() %7B%0A        return maxLevel;%0A    %7D%0A%0A    /**%0A     * Sets the current battery decrease rate (i.e. amount with which the%0A     * battery decreases at every trace tick).%0A     *%0A     * @param decreaseRate%0A     */%0A    public void setDecreaseRate(double decreaseRate) %7B%0A        this.decreaseRate = decreaseRate
 ;%0A  
@@ -2883,10 +2883,24 @@
 evel
---
+ -= decreaseRate
 ;%0A%0A 

Add a customizable decrease rate to battery life