if i may contribute an idea, i've seen some games where units gain experience through merely doing damage to an enemy unit. so, here's what i propose: a unit would acquire the percentage of damage dealt to the the enemy's HP as experience. eg. if a unit dealt an attack that drained 10% of the enemy's health, it would gain 10% of the max amount of XP that the attacked unit has (small damage quabbles would be rounded up, for ease of use). now, this system would always apply, even if the unit in question is healed.
also worth noting, this should also create a new tag for units - "xp-gain" which, in short acts like this: in the previous scenario, if the attacking unit had an <xp-gain value ="2"/> somewhere in his parameters, he would receive 20% of the possible xp. (this tag would default to 1, because it's a multiplier)
Me likes. That would be simpler to implement (get the percentage of damage done (damage dealt divided by max HP) and then multiply that to the specified experience (or max HP if none is specified).
To make sure I understand correctly, the
xp-gain tag would multiply the amount of experience the unit should have gained. So if they dealt 100 damage to a unit without specified experience tag (first post; no specified experience tag would have the experience given equal the unit's max HP, so the damage you deal is the experience you get). Being a multiplier, having an xp-gain value of 1 would give you 100 xp, whereas having an xp-gain value of 0.5 would only give you 50 xp, and an xp-gain value of 2 would give you 200. However, then your example is incorrect, as "2" would double the xp, "0.2" would give 20%.
If that is what you mean by the tag, then I question the usefulness of this tag, as you can already control the amount of experience needed for the level. So a unit that needs 3000 xp to gain a level and has an xp-gain value of 0.5 would be the same as a unit that needs 6000 xp to gain that level with an xp gain of 1 (the equivalent of no xp gain).
I'm actually having a hard time putting this into (understandable) words, so some quick examples to the extent of my understanding:
Example One:Swordman has 700 HP, and no specified
experience tag, so the experience from defeating it (entirely) would be 700. An opposing guard attacks the swordman dealing 100 damage. Mathmatically,
100 / 700 * 700 = 100 (that is, damage divided by max HP times the experience value), so the guard got 100 xp from that attack.
Example Two:Swordman has 700 HP, but has an
experience tag with the value of 1000. Thus, defeating it would give 1000 xp. An opposing guard attacks the swordman, dealing 100 damage. Mathmatically,
100 / 700 * 1000 = 143, so the guard got 143 xp from that attack (we'll assume we should always be rounding up, or ceiling, the number).
Example Three:Archmage has 450 HP, but has an
experience tag with a hefty 1500. A guard attacks if for 150 damage. Mathmatically,
150 / 450 * 1500 = 500. The guard took off a third of its health, so it gets a third of the experience from defeating the archmage.
Why the math?The experience value is the total experience gained from the unit if you were to kill them without them healing at all. So if a swordman is worth 1000 xp, and I kill it (miraculously) in a single hit, I should get 1000 xp from that kill. So if I took off half the unit's HP, I should be getting half of the total xp from killing them, namely 1000. If I took off 10% of its HP, I should be getting 10% of the total xp (that is, 100). So dividing the damage dealt by the total HP gives me the percentage of damage done, which we multiply by the experience value, getting the experience that one blow gave us.
On a side note, the whole concept of granted xp based on damage means that units which have an area of effect attack would be gaining xp a lot faster than normal (whatever your normal is), since they can hit a lot of units, which would have to be taken into aspect by modders.