Rewriting Classes
From Serious Sam's Bogus Detour
Rewriting behaviors is a useful method for overwriting the behavior of certain classes used in units of which you don't have an easy way of rewriting the unit file. For example, this method can be used to modify or add functionality to the Player
behavior. To do this, you will have to create a class and inherit it from the original behavior. So, for the Player
example:
class MyPlayer : Player { MyPlayer(UnitPtr unit, SValue& params) { super(unit, params); } void Update(int dt) override { Player::Update(dt); // Do stuff! } }
Then, in your scenario's info.xml file, add the following:
<classmaps> <behavior from="Player" to="MyPlayer" /> </classmaps>
Now when you start your Scenario, MyPlayer
will be used instead of Player
.
The same can be accomplished for objects instantiated via InstantiateClass
(for example the Damage
effect), using the script
tag. Gamemode classes can also be rewritten using the gamemode
tag.
<classmaps> <script from="Damage" to="MyDamage" /> <gamemode from="Survival" to="MySurvival" /> </classmaps>