161 | | ==== Cosing the carriers ==== |
| 161 | ==== Coosing the carriers ==== |
| 162 | You also have to choose the carriers that are allowed to pick your pickup up. After you have chosen the entity that carries your pickup you need to do the following. |
| 163 | * The enity that carries your pickup needs to be derived from the PickupCarrier interface. And you need to implement the PickupCarriers virtual functions getCarrierChildren() and getCarrierParent(). Now let me explain, very briefly, why these functions are needed. All pickups are initially picked up by a pawn and the "propagated", or handed down to the entity that carries them. With the above mentioned two function just that is done. A hierarchical structure is established with one parent and a set of children, where the Pawn is the root node of this hierarchical structure, the only entity with no parent. |
| 164 | * Once you have done that you will also want to specify in your pickup by which carriers it can be picked up, this is done via the addTarget() function. So you have to make sure the target is added whenever one of your pickups is created (so, most conveniently somewhere in the constructor), with the following command. |
| 165 | {{{ |
| 166 | this->addTarget(ClassIdentifier<MyCarrierClass>::getIdentifier()); |
| 167 | }}} |
163 | | work in progress... |
| 169 | ==== Creating the inner workings of your pickup ==== |
| 170 | Now that we have the skeleton of a pickup and we have defined which carriers are allowed to pick our pickup up we are going to take a look at all the methods we can (or sometimes have to) overload from Pickupable, for our pickup to work properly. Bu firstly I will introduce some more concepts to make the need for these methods more obvious. |
| 171 | * Since one pickup class can itself be many pickup types we need a way to find out whether a particular instance of a pickup is of the same type as another instance of a pickup. To that end the PickupIdentifier (in the following just called identifier) was created. The PickupIdentifier accounts for the type of class your pickup is of and also for the parameters (and their values) that distinguish different types of pickups of the same class. Much of the functionality of the pickup module relies on this identifier being correct, thus it is very important to initialize it correctly. (We will see, how that is done in a short while.) |
| 172 | * Every pickup has at least two states which are very important. The first is, whether the pickup is currently in use or not and the second is whether the pickup is currently picked up or not. |
| 173 | |
| 174 | Now lets look at the important methods. |
| 175 | * changedUsed() The changedUsed() method is called whenever the state of the pickup transits from being used to not being used or the other way around. Which means this method is probably the most important method you have at your fingertips, since it enables you to apply the effect of your pickup when it gets used and remove the effect as soon as it is no longer in use. |
| 176 | * changedPickedUp() The changedPickedUp() method is called whenever the state of the pickup changes from being picked up to not being picked up or the other way around. For example if you want your pickup to be used as soon as it is picked up, this is the method you have to overload to achieve that behavior (or just let your pickup be derived from Pickup, which implements exactly that behavior if the activationType is set to 'immediate'). You don't have to concern yourself with destroying the pickup or creating a spawner when it changes to not picked up, since that is already implemented with the Pickupable and PickupCarrier class. If you want a different behavior, however once again, this is the method. |
| 177 | * changedCarrier() The changedCarrier() method is called whenever the carrier of the pickup changes. And by that I don't mean the class that is allowed to carry the pickup, but the object that actually carries (or carried) the pickup. Please do not overload this class to implement behavior for picked up -> not picked up transitions, use changedPickedUp() for that. For most pickup classes this method doesn't need to be overloaded, one use for it, however is in the PickupCollection class, where the new carrier needed to be communicated to all pickups the collection consists of, whenever the carrier was changed. |
| 178 | |
| 179 | Please be aware, that these three methods are methods registered with Super, meaning, that whenever overloading them, don't forget to call SUPER(MyClass, myMethod); |
| 180 | |
| 181 | * a |