@Override public boolean okMessage(Environmental host, CMMsg msg) { if (msg.amITarget(this)) { switch (msg.targetMinor()) { case CMMsg.TYP_ACTIVATE: if (!isInstalled()) { if (!CMath.bset(msg.targetMajor(), CMMsg.MASK_CNTRLMSG)) msg.source().tell(L("@x1 is not installed or connected.", name())); return false; } else if (!isAllWiringHot(this)) { if (!CMath.bset(msg.targetMajor(), CMMsg.MASK_CNTRLMSG)) msg.source() .tell(L("The panel containing @x1 is not activated or connected.", name())); return false; } break; case CMMsg.TYP_DEACTIVATE: break; case CMMsg.TYP_LOOK: break; case CMMsg.TYP_POWERCURRENT: if ((!(this instanceof FuelConsumer)) && (!(this instanceof PowerGenerator)) && activated() && (powerNeeds() > 0) && (msg.value() > 0)) { double amtToTake = Math.min((double) powerNeeds(), (double) msg.value()); msg.setValue(msg.value() - (int) Math.round(amtToTake)); amtToTake *= getFinalManufacturer().getEfficiencyPct(); if (subjectToWearAndTear() && (usesRemaining() <= 200)) amtToTake *= CMath.div(usesRemaining(), 100.0); setPowerRemaining(Math.min(powerCapacity(), Math.round(amtToTake) + powerRemaining())); } break; } } return super.okMessage(host, msg); }
@Override public int powerNeeds() { return (int) Math.min((powerCapacity - power), getRechargeRate()); }