Yes, you're right, it would have had to be protected, I didn't catch that.
Thanks for the help, folks. I ended up coming up with exactly the same question in a different context, but this time I knew what the answer was.
There is a base Entity class from which Creature and Item are both derived. It has the following methods:
public void damage(int damage, Shared.DamageType type) {
// consider ranged vs. melee, also using some set of constants for damage type
integrity -= damage;
if (integrity <= 0) {
integrity = 0;
destroy();
}
}
protected void destroy() {
// Remove from entity manager
// Leave things like debris or a corpse as appropriate
GameFlow.getInstance().getMessageLog().post(
"Entity destroyed.");
}
Creatures and Items are both handled by separate managers, so they override the destroy method and remove themselves from the appropriate manager. Thanks to some of the explanations I received earlier, I was able to work it out so that the Creature class could call super.damage() within its damage method, and still use the appropriate destroy method (that within Creature, not Entity):
public void damage(int damage, Shared.DamageType type) {
// Armor reduces sharp damage
if (armored) {
if (type == Shared.DamageType.SHARP) {
damage = (int) (damage * Shared.DAMAGE_RESISTANCE);
}
if (armor != null) {
// If we're wearing armor (as opposed to natural armor)
int armorDamage = (int) (Shared.ARMOR_DAMAGE_PORTION * damage);
armor.damage(armorDamage, type);
damage -= armorDamage;
}
}
if (armored == false) {
if (type == Shared.DamageType.BLUNT) {
damage *= Shared.DAMAGE_RESISTANCE;
}
}
super.damage(damage, type);
// Damage effect
EffectManager.addEffect(position);
}
protected void destroy() {
// Remove from entity manager
currentArea.removeCreatureFromCell(this, position);
currentArea.getCreatureManager().removeCreature(this);
// Leave things like debris or a corpse as appropriate
GameFlow.getInstance().getMessageLog().post(
"Creature killed.");
}
So the base damage code is reused via super.damage() within the Creature damage method, and it still calls the correct Creature destroy() method. Thanks again, I would have been really confused had it not been for your assistance earlier.